Bug #65312 [Com]: Segmentation fault with filesize=4096
Edit report at https://bugs.php.net/bug.php?id=65312&edit=1
ID: 65312
Comment by: ricardohenrylee at gmail dot com
Reported by: bee8192 at gmail dot com
Summary: Segmentation fault with filesize=4096
Status: Duplicate
Type: Bug
Package: *General Issues
Operating System: Win7x64+Cygwin
PHP Version: 5.5.1
Block user comment: N
Private report: N
New Comment:
PHP mmap()s source files as it it faster than using normal I/O.
The problem is with the page size in Cygwin. When a file is mmap()ed to memory, any remaining bytes
after the EOF in the last page are zero'ed out. So when PHP reads the bytes after the EOF, it
expects to find zeroes.
In most systems the page size is 4K. In Windows the page size is also 4K, but aligned to a boundary
of 64K (allocation granularity). Cygwin reconciles this by making the page size 64K. So in reality,
Cygwin pages are 64K big, backed by 4K pages allocated along 64K boundaries.
When PHP reads a file, it looks at the file size. If there are enough bytes to read ahead in the
last memory page after the EOF, PHP will use mmap. Else it will open the file normally.
When PHP is given a 4K file on Cygwin, it sees that the file and the bytes for reading ahead will
easily fit into a 64K page (in Cygwin). So it mmap()s the file. However only one 4K page (in
Windows) is mapped to. The remaining 60K pages are not. When PHP reads ahead past the EOF, it reads
into page which has not been mapped to. This results in a segfault.
Changing the REAL_PAGE_SIZE to 4096 fixes the issue.
This bug is not a duplicate of any other bug as it is to do solely with the way Cygwin handles
memory paging.
This definition needs to be fixed in two places as there are two different places where a PHP source
file can be mmap()ed, depending on whether it is loaded using php-cli or loaded when php is run from
a library. Please see the patch that I will attach.
Previous Comments:
------------------------------------------------------------------------
[2015-10-26 21:42:51] sabel at altmuehlnet dot de
This also occurs with a file size of 8192 bytes!
------------------------------------------------------------------------
[2013-07-24 10:14:40] ab@php.net
see bug #52752
------------------------------------------------------------------------
[2013-07-24 09:53:58] ab@php.net
Related To: Bug #64996
------------------------------------------------------------------------
[2013-07-24 09:51:34] ab@php.net
This bug might be not related to phar or your particular
environment. Looking through the bug tracker I find your backtrace is related to
bug #65091, bug #52752, bug #65091, bug #64883 and maybe bug #61186
------------------------------------------------------------------------
[2013-07-24 09:16:10] ab@php.net
Hi again. Could you please also post the ./configure arguments?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=65312
--
Edit this bug report at https://bugs.php.net/bug.php?id=65312&edit=1
Thread (9 messages)