php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1470 ImageGif outputs bad image
Submitted: 1999-05-30 03:55 UTC Modified: 1999-06-01 07:07 UTC
From: xuyifeng at telekbird dot com dot cn Assigned:
Status: Closed Package: Other
PHP Version: 3.0.6 OS: WindowsNT
Private report: No CVE-ID: None
 [1999-05-30 03:55 UTC] xuyifeng at telekbird dot com dot cn
I am current using PHP3.06 for Win32, I have found that the PHP author made a same mistaken with me,
PHP uses standard C runtime library function fwrite (or write ?) to output binary data, this will produce
unexpected result, because under Microsoft Windows/NT, standard output is always opened as text mode,
this means that if you output char '\n', it will be outputed as '\r\n',  0x0a will be output as 0x0d0a, so if 
your image contains char 0x0a,  when you output image data, it will outputs 0x0d0a, and the image stream
is damaged.

to avoid this problem,  there is two methods:
1)
    PHP should call _setmode functions when it startups,
    result = _setmode( _fileno( stdout ),  _O_BINARY);

    this also resolves another problem:
    PHP program want to send binary data to user client, but binary stream is changed unexpected.

2)
   use Win32 API WriteFile,  this function needs a Win32 file handle,
   to get Win32 file handle,  you should use   _fileno and _get_osfhandle,  the later  function is in io.h.

I recommand use first method.
I know Microsoft Windows sucks, but it exists there,  we need deal with it.

sorry for my poor english,  because I am in China, it isn't my native language.
I wish PHP make better and better.

XuYifeng

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-01 07:07 UTC] xuyifeng at telekbird dot com dot cn
Image functions not support under win32 ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC