php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23396 Fix for debug mode assertion failure in the Win2000 native libraries of fdopen
Submitted: 2003-04-28 23:24 UTC Modified: 2003-05-15 13:18 UTC
From: ed000001 at hotmail dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 4.3.1 OS: Win2000 - Debug Mode
Private report: No CVE-ID: None
 [2003-04-28 23:24 UTC] ed000001 at hotmail dot com
Problem:

Initialization phase (before script) debug mode assertion failure in the Win32 native libraries where "fdopen.c" is implemented when compiling "php4ts_cli" in "Win32 Debug_TS".

Development Environment "Fix":

Do not call dup() for the Win32 platform -- I have not check the implications as this is not my prod environment.

File php_fopen_wrapper.c:
=========================

#ifdef PHP_WIN32
 #define FIX_DUP(a)    (a)
#else
 #define FIX_DUP(a)    (dup((a))
#endif

php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
    FILE * fp = NULL;
    php_stream * stream = NULL;

    if (!strncasecmp(path, "php://", 6))
        path += 6;
    
    if (!strcasecmp(path, "output")) {
        return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb");
    }
    
    if (!strcasecmp(path, "input")) {
        return php_stream_alloc(&php_stream_input_ops, NULL, 0, "rb");
    }  
    
    if (!strcasecmp(path, "stdin")) {
        fp = fdopen(FIX_DUP(STDIN_FILENO), mode);
    } else if (!strcasecmp(path, "stdout")) {
        fp = fdopen(FIX_DUP(STDOUT_FILENO), mode);
    } else if (!strcasecmp(path, "stderr")) {
        fp = fdopen(FIX_DUP(STDERR_FILENO), mode);
    }

    if (fp)    {
        stream = php_stream_fopen_from_file(fp, mode);
        if (stream == NULL)
            fclose(fp);
    }
    return stream;
}

Thanks for the great tool!

Ed

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-28 23:28 UTC] ed000001 at hotmail dot com
comment
 [2003-04-28 23:29 UTC] ed000001 at hotmail dot com
There is an extra "(" in the "(dup((a))" which should be (dup(a))
 [2003-04-29 04:42 UTC] wez@php.net
Can you give a little more detail on what error is caused and how it is triggered?

It works fine here in my dev env under winxp.

Have you tried the source of the latest stable snapshot, or the latest RC?

http://qa.php.net/
http://snaps.php.net/
 [2003-04-29 20:21 UTC] ed000001 at hotmail dot com
I run Win2000 5.00.2195 with Service Pack 3.  The development environment is Visual C++ 6.0.  I downloaded and installed php-4.3.1.tar.gz as instructed here http://php.lamphost.net/manual/en/install.windows.php 

I also created an empty C:\work\php-4.3.1\ext\mysql\libmysql\ dll.c as the php-4.3.1 tree comes with a zero length file, which will no uncompress under WinZip for Win32.

I followed the remaining instructions in http://php.lamphost.net/manual/en/install.windows.php and compiled the php4ts_cli with the "Win32 Debug_TS" built.  Then I created a test script "a.php" which reads like

<?
echo "hello world";
?>

When I run it in debug mode with the parameter "?f a.php"  the assertion triggers (unless I make the modifications described above).  Note that this is a VC++ Win32 library assertion and if you do not have the debug versions of these libraries in your machine it may not trigger.  Below is the code in fdopen.c that kicks out the assertion.

FILE * __cdecl _tfdopen (
        int filedes,
        REG2 const _TSCHAR *mode
        )
{
        REG1 FILE *stream;
        int whileflag, tbflag, cnflag;

        _ASSERTE(mode != NULL);

#if defined (_WIN32)

        _ASSERTE((unsigned)filedes < (unsigned)_nhandle);
        _ASSERTE(_osfile(filedes) & FOPEN);		<<= assertion triggered

The value for filedes is "4".

If I remember right there will be no error reported if you compile the Release version of the project, which is something I do not do.  I use the Win32 environment only to develop/debug a php extension.

Thanks
 [2003-05-15 13:18 UTC] sniper@php.net
You were asked to try the snapshots, not 4.3.1.
Seems like bogus to me if it works for Wez.

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Jun 17 08:00:02 2026 UTC