From:
Operating system: FreeBSD 7.4-RELEASE-p3
PHP version: 5.3.10
Package: *General Issues
Bug Type: Bug
Bug description:fopen and O_NONBLOCK
Description:
------------
The use of the flag of N in the fopen leads to what fread returns an empty
string. Subsequent calls to fread not change the situation.
Test script:
---------------
<?php
Mode rb
$fp = fopen('test.bin', 'rb');
fread($fp, 10);
?>
Mode rbn
<?php
$fp = fopen('test.bin', 'rbn');
fread($fp, 10);
?>
Actual result:
--------------
Ktrace dumps
Mode rb
21490 php GIO fd 3 read 58 bytes
"<?php
$fp = fopen('test.bin', 'rb');
fread($fp, 10);
?>"
21490 php RET read 58/0x3a
21490 php CALL lseek(0x3,0,SEEK_SET,0x1)
21490 php RET lseek 58/0x3a
21490 php CALL sigaction(SIGPROF,0xbfbfe984,0xbfbfe96c)
21490 php RET sigaction 0
21490 php CALL sigprocmask(SIG_UNBLOCK,0xbfbfe9c4,0)
21490 php RET sigprocmask 0
21490 php CALL gettimeofday(0xbfbfe8f8,0)
21490 php RET gettimeofday 0
21490 php CALL fstat(0,0xbfbfe8d4)
21490 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570188, stime=1333570188,
ctime=1333570188, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21490 php RET fstat 0
21490 php CALL fstat(0,0x28720de0)
21490 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570188, stime=1333570188,
ctime=1333570188, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21490 php RET fstat 0
21490 php CALL lseek(0,0,SEEK_SET,0x1)
21490 php RET lseek 265513/0x40d29
21490 php CALL fstat(0x1,0xbfbfe8d4)
21490 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570188, stime=1333570188,
ctime=1333570188, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21490 php RET fstat 0
21490 php CALL fstat(0x1,0x28720f4c)
21490 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570188, stime=1333570188,
ctime=1333570188, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21490 php RET fstat 0
21490 php CALL lseek(0x1,0,SEEK_SET,0x1)
21490 php RET lseek 265513/0x40d29
21490 php CALL fstat(0x2,0xbfbfe8d4)
21490 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570188, stime=1333570188,
ctime=1333570188, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21490 php RET fstat 0
21490 php CALL fstat(0x2,0x287210a4)
21490 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570188, stime=1333570188,
ctime=1333570188, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21490 php RET fstat 0
21490 php CALL lseek(0x2,0,SEEK_SET,0x1)
21490 php RET lseek 265513/0x40d29
21490 php CALL __getcwd(0xbfbfd104,0x400)
21490 php NAMI "/usr/home/Null"
21490 php RET __getcwd 0
21490 php CALL gettimeofday(0xbfbfcb98,0)
21490 php RET gettimeofday 0
21490 php CALL lstat(0xbfbfccc4,0xbfbfcc28)
21490 php NAMI "/usr/home/Null/read.php"
21490 php STRU struct stat {dev=83, ino=2032746, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8113575, atime=1333570188, stime=1333661027,
ctime=1333570174, birthtime=1333554129, size=58, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET lstat 0
21490 php CALL lstat(0xbfbfccc4,0xbfbfcb08)
21490 php NAMI "/usr/home/Null"
21490 php STRU struct stat {dev=83, ino=2028854, mode=drwxr-xr-x ,
nlink=3, uid=1001, gid=0, rdev=8102431, atime=1333570174, stime=1333570188,
ctime=1333570188, birthtime=1333557050, size=512, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET lstat 0
21490 php CALL lstat(0xbfbfccc4,0xbfbfc9f8)
21490 php NAMI "/usr/home"
21490 php STRU struct stat {dev=83, ino=2028853, mode=drwxr-xr-x ,
nlink=3, uid=0, gid=0, rdev=8102430, atime=1333566943, stime=1333557050,
ctime=1333557050, birthtime=1333557050, size=512, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET lstat 0
21490 php CALL lstat(0xbfbfccc4,0xbfbfc8e8)
21490 php NAMI "/usr"
21490 php STRU struct stat {dev=83, ino=2001920, mode=drwxr-xr-x ,
nlink=16, uid=0, gid=0, rdev=7997488, atime=1333569707, stime=1333543830,
ctime=1333543830, birthtime=1297914801, size=512, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET lstat 0
21490 php CALL ioctl(0x3,TIOCGETA,0xbfbfd378)
21490 php RET ioctl -1 errno 25 Inappropriate ioctl for device
21490 php CALL fstat(0x3,0xbfbfd3cc)
21490 php STRU struct stat {dev=83, ino=2032746, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8113575, atime=1333570188, stime=1333661027,
ctime=1333570174, birthtime=1333554129, size=58, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET fstat 0
21490 php CALL __sysctl(0xbfbfd388,0x2,0xbfbfd394,0xbfbfd398,0,0)
21490 php SCTL "p1003_1b.pagesize"
21490 php RET __sysctl 0
21490 php CALL mmap(0,0x5a,PROT_READ,MAP_PRIVATE,0x3,0,0)
21490 php RET mmap 678326272/0x286e7000
21490 php CALL munmap(0x286e7000,0x3a)
21490 php RET munmap 0
21490 php CALL close(0x3)
21490 php RET close 0
21490 php CALL __getcwd(0xbfbfcee4,0x400)
21490 php NAMI "/usr/home/Null"
21490 php RET __getcwd 0
21490 php CALL gettimeofday(0xbfbfc978,0)
21490 php RET gettimeofday 0
21490 php CALL lstat(0xbfbfcaa4,0xbfbfca08)
21490 php NAMI "/usr/home/Null/test.bin"
21490 php STRU struct stat {dev=83, ino=2032747, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8105130, atime=1333570019, stime=1333660846,
ctime=1333569993, birthtime=1333569993, size=1666, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET lstat 0
21490 php CALL open(0x28721238,O_RDONLY,<unused>0)
21490 php NAMI "/usr/home/Null/test.bin"
21490 php RET open 3
21490 php CALL fstat(0x3,0x28721734)
21490 php STRU struct stat {dev=83, ino=2032747, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8105130, atime=1333570019, stime=1333660846,
ctime=1333569993, birthtime=1333569993, size=1666, blksize=16384, blocks=4,
flags=0x0 }
21490 php RET fstat 0
21490 php CALL lseek(0x3,0,SEEK_SET,0x1)
21490 php RET lseek 0
21490 php CALL read(0x3,0x28722914,0x2000)
21490 php GIO fd 3 read 1666 bytes
"test binary data test binary data test binary data test binary data
test binary data test binary data test binary data test binary data test
binary data test binary data\
test binary data test binary data test binary data test binary data
test
binary data test binary data test binary data test binary data test binary
data test binary dat\
a test binary data test binary data test binary data test binary data
test
binary data test binary data test binary data test binary data test binary
data test binary da\
ta test binary data test binary data test binary data test binary data
test binary data test binary data test binary data test binary data test
binary data test binary d\
ata test binary data test binary data test binary data test binary data
test binary data test binary data test binary data test binary data test
binary data test binary \
data test binary data test binary data test binary data test binary data
test binary data test binary data test binary data test binary data test
binary data test binary\
data test binary data test binary data test binary data test binary
data
test binary data test binary data test binary data test binary data test
binary data test binar\
y data test binary data test binary data test binary data test binary
data
test binary data test binary data test binary data test binary data test
binary data test bina\
ry data test binary data test binary data test binary data test binary
data test binary data test binary data test binary data test binary data
test binary data test bin\
ary data test binary data test binary data test binary data test binary
data test binary data test binary data test binary data test binary data "
21490 php RET read 1666/0x682
21490 php CALL close(0x3)
21490 php RET close 0
21490 php CALL close(0x2)
21490 php RET close 0
21490 php CALL close(0x1)
21490 php RET close 0
21490 php CALL close(0)
21490 php RET close 0
21490 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe94c)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe91c)
21490 php RET sigprocmask 0
21490 php CALL munmap(0x286e0000,0x7000)
21490 php RET munmap 0
21490 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe94c)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe91c)
21490 php RET sigprocmask 0
21490 php CALL munmap(0x286a0000,0x6000)
21490 php RET munmap 0
21490 php CALL munmap(0x286a6000,0x3a000)
21490 php RET munmap 0
21490 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe97c)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe94c)
21490 php RET sigprocmask 0
21490 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21490 php RET sigprocmask 0
21490 php CALL exit(0)
Mode rbn
21488 php GIO fd 3 read 59 bytes
"<?php
$fp = fopen('test.bin', 'rbn');
fread($fp, 10);
?>"
21488 php RET read 59/0x3b
21488 php CALL lseek(0x3,0,SEEK_SET,0x1)
21488 php RET lseek 59/0x3b
21488 php CALL sigaction(SIGPROF,0xbfbfe984,0xbfbfe96c)
21488 php RET sigaction 0
21488 php CALL sigprocmask(SIG_UNBLOCK,0xbfbfe9c4,0)
21488 php RET sigprocmask 0
21488 php CALL gettimeofday(0xbfbfe8f8,0)
21488 php RET gettimeofday 0
21488 php CALL fstat(0,0xbfbfe8d4)
21488 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570056, stime=1333570056,
ctime=1333570056, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21488 php RET fstat 0
21488 php CALL fstat(0,0x28720de0)
21488 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570056, stime=1333570056,
ctime=1333570056, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21488 php RET fstat 0
21488 php CALL lseek(0,0,SEEK_SET,0x1)
21488 php RET lseek 265177/0x40bd9
21488 php CALL fstat(0x1,0xbfbfe8d4)
21488 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570056, stime=1333570056,
ctime=1333570056, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21488 php RET fstat 0
21488 php CALL fstat(0x1,0x28720f4c)
21488 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570056, stime=1333570056,
ctime=1333570056, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21488 php RET fstat 0
21488 php CALL lseek(0x1,0,SEEK_SET,0x1)
21488 php RET lseek 265177/0x40bd9
21488 php CALL fstat(0x2,0xbfbfe8d4)
21488 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570056, stime=1333570056,
ctime=1333570056, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21488 php RET fstat 0
21488 php CALL fstat(0x2,0x287210a4)
21488 php STRU struct stat {dev=50396928, ino=97, mode=crw--w---- ,
nlink=1, uid=1001, gid=4, rdev=97, atime=1333570056, stime=1333570056,
ctime=1333570056, birthtime=-1, size=0, blksize=4096, blocks=0, flags=0x0
}
21488 php RET fstat 0
21488 php CALL lseek(0x2,0,SEEK_SET,0x1)
21488 php RET lseek 265177/0x40bd9
21488 php CALL __getcwd(0xbfbfd104,0x400)
21488 php NAMI "/usr/home/Null"
21488 php RET __getcwd 0
21488 php CALL gettimeofday(0xbfbfcb98,0)
21488 php RET gettimeofday 0
21488 php CALL lstat(0xbfbfccc4,0xbfbfcc28)
21488 php NAMI "/usr/home/Null/read.php"
21488 php STRU struct stat {dev=83, ino=2032746, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8113575, atime=1333570056, stime=1333660883,
ctime=1333570030, birthtime=1333554129, size=59, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET lstat 0
21488 php CALL lstat(0xbfbfccc4,0xbfbfcb08)
21488 php NAMI "/usr/home/Null"
21488 php STRU struct stat {dev=83, ino=2028854, mode=drwxr-xr-x ,
nlink=3, uid=1001, gid=0, rdev=8102431, atime=1333570052, stime=1333570056,
ctime=1333570056, birthtime=1333557050, size=512, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET lstat 0
21488 php CALL lstat(0xbfbfccc4,0xbfbfc9f8)
21488 php NAMI "/usr/home"
21488 php STRU struct stat {dev=83, ino=2028853, mode=drwxr-xr-x ,
nlink=3, uid=0, gid=0, rdev=8102430, atime=1333566943, stime=1333557050,
ctime=1333557050, birthtime=1333557050, size=512, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET lstat 0
21488 php CALL lstat(0xbfbfccc4,0xbfbfc8e8)
21488 php NAMI "/usr"
21488 php STRU struct stat {dev=83, ino=2001920, mode=drwxr-xr-x ,
nlink=16, uid=0, gid=0, rdev=7997488, atime=1333569707, stime=1333543830,
ctime=1333543830, birthtime=1297914801, size=512, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET lstat 0
21488 php CALL ioctl(0x3,TIOCGETA,0xbfbfd378)
21488 php RET ioctl -1 errno 25 Inappropriate ioctl for device
21488 php CALL fstat(0x3,0xbfbfd3cc)
21488 php STRU struct stat {dev=83, ino=2032746, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8113575, atime=1333570056, stime=1333660883,
ctime=1333570030, birthtime=1333554129, size=59, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET fstat 0
21488 php CALL __sysctl(0xbfbfd388,0x2,0xbfbfd394,0xbfbfd398,0,0)
21488 php SCTL "p1003_1b.pagesize"
21488 php RET __sysctl 0
21488 php CALL mmap(0,0x5b,PROT_READ,MAP_PRIVATE,0x3,0,0)
21488 php RET mmap 678326272/0x286e7000
21488 php CALL munmap(0x286e7000,0x3b)
21488 php RET munmap 0
21488 php CALL close(0x3)
21488 php RET close 0
21488 php CALL __getcwd(0xbfbfcee4,0x400)
21488 php NAMI "/usr/home/Null"
21488 php RET __getcwd 0
21488 php CALL gettimeofday(0xbfbfc978,0)
21488 php RET gettimeofday 0
21488 php CALL lstat(0xbfbfcaa4,0xbfbfca08)
21488 php NAMI "/usr/home/Null/test.bin"
21488 php STRU struct stat {dev=83, ino=2032747, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8105130, atime=1333570019, stime=1333660846,
ctime=1333569993, birthtime=1333569993, size=1666, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET lstat 0
21488 php CALL open(0x28721238,O_WRONLY|O_NONBLOCK,<unused>0)
21488 php NAMI "/usr/home/Null/test.bin"
21488 php RET open 3
21488 php CALL fstat(0x3,0x28721734)
21488 php STRU struct stat {dev=83, ino=2032747, mode=-rw-r--r-- ,
nlink=1, uid=1001, gid=0, rdev=8105130, atime=1333570019, stime=1333660846,
ctime=1333569993, birthtime=1333569993, size=1666, blksize=16384, blocks=4,
flags=0x0 }
21488 php RET fstat 0
21488 php CALL lseek(0x3,0,SEEK_SET,0x1)
21488 php RET lseek 0
21488 php CALL read(0x3,0x28722914,0x2000)
21488 php RET read -1 errno 9 Bad file descriptor
21488 php CALL close(0x3)
21488 php RET close 0
21488 php CALL close(0x2)
21488 php RET close 0
21488 php CALL close(0x1)
21488 php RET close 0
21488 php CALL close(0)
21488 php RET close 0
21488 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe94c)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe91c)
21488 php RET sigprocmask 0
21488 php CALL munmap(0x286e0000,0x7000)
21488 php RET munmap 0
21488 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe94c)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe91c)
21488 php RET sigprocmask 0
21488 php CALL munmap(0x286a0000,0x6000)
21488 php RET munmap 0
21488 php CALL munmap(0x286a6000,0x3a000)
21488 php RET munmap 0
21488 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe97c)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_BLOCK,0x282e7b00,0xbfbfe94c)
21488 php RET sigprocmask 0
21488 php CALL sigprocmask(SIG_SETMASK,0x282e7b10,0)
21488 php RET sigprocmask 0
21488 php CALL exit(0)
--
Edit bug report at https://bugs.php.net/bug.php?id=61645&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=61645&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=61645&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=61645&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=61645&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=61645&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=61645&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=61645&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=61645&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=61645&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=61645&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=61645&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=61645&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=61645&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=61645&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=61645&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61645&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=61645&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=61645&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=61645&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=61645&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=61645&r=mysqlcfg