php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75894 php_stream_input_seek() broken
Submitted: 2018-01-31 16:28 UTC Modified: 2021-07-20 09:59 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: davide dot romanini at gmail dot com Assigned: cmb (profile)
Status: Feedback Package: Streams related
PHP Version: 7.1.14RC1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: davide dot romanini at gmail dot com
New email:
PHP Version: OS:

 

 [2018-01-31 16:28 UTC] davide dot romanini at gmail dot com
Description:
------------
The php://input stream behaves differently from other standard streams. In particular, seeking is completely broken. Basically the stream works only when used forward-only, consume-once (eg: file_get_contents('php://input')).

I didn't found the bug reported here (I searched under streams related bugs using the 'seek' keyword). 

I sketched a possible fix with tests here: https://github.com/php/php-src/compare/PHP-7.1...davide-romanini:fix-php-stream-input-seek

Test script:
---------------
--POST--
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ante ex, placerat nec sollicitudin vitae, ultricies molestie nisi. Maecenas lacus magna, augue.
--FILE--
<?php
$i = fopen('php://input', 'r');
fseek($i, 5);
var_dump(fread($i, 10));
rewind($i);
var_dump(fread($i, 5));
fseek($i, -6, SEEK_END);
var_dump(fread($i, 6));
?>
--EXPECT--
string(10) " ipsum dol"
string(5) "Lorem"
string(6) "augue."


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-20 09:59 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-07-20 09:59 UTC] cmb@php.net
> Basically the stream works only when used forward-only,
> consume-once (eg: file_get_contents('php://input')).

This is actually what I would expect.  Maybe that needs to be
documented more clearly?  Wrt. your patch – did you consider to
make a pull request[1]?

[1] <https://github.com/php/php-src/pulls>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jul 26 04:01:24 2021 UTC