php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51854 stream_set_read_buffer() not working as expected
Submitted: 2010-05-18 19:57 UTC Modified: 2010-05-18 21:40 UTC
From: datibbaw@php.net Assigned: pajoye (profile)
Status: Closed Package: Streams related
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
 [2010-05-18 19:57 UTC] datibbaw@php.net
Description:
------------
Recently, the stream_set_read_buffer() was introduced; it's signature suggests that a buffer size can be set.

However, when passing any non-zero value, the stream becomes unbuffered.

This is because of a missing check inside _php_stream_set_option():

if (value == PHP_STREAM_BUFFER_NONE) {
    stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
} else {
    stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER;
}

Test script:
---------------
<?php

$f = fopen('/dev/urandom', 'rb');
// setting read buffer to 1024
stream_set_read_buffer($f, 1024);
// reading the first 10 bytes
$s = fread($f, 10);
fclose($f);

/*
========= STRACE OUTPUT =========

open("/dev/urandom", O_RDONLY)          = 3
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "\3X\264\rQ\277\273\367\347Z", 10) = 10
close(3)                                = 0
*/
?>

Expected result:
----------------
Either the read() loads 1024 bytes, which would be ideal, or it should still load the default buffer size (8192 bytes).

The attached patch addresses the latter behaviour.


Patches

set_read_buffer_patch_v2 (last revision 2010-05-18 19:40 UTC by tjerk dot meesters at gmail dot com)
php_stream_set_option_read_buffer (last revision 2010-05-18 18:00 UTC by tjerk dot meesters at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-18 21:39 UTC] pajoye@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=299466
Log: - #51854, fix logic (patch by Tjerk)
 [2010-05-18 21:40 UTC] pajoye@php.net
-Status: Open +Status: Closed -Operating System: Linux +Operating System: * -Assigned To: +Assigned To: pajoye
 [2010-05-18 21:40 UTC] pajoye@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 17:01:30 2024 UTC