Req #44392 [Asn->Ana]: getFilePointer() for Childs of SplFileObject

From: Date: Sun, 22 Jan 2017 16:10:58 +0000
Subject: Req #44392 [Asn->Ana]: getFilePointer() for Childs of SplFileObject
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206859@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=44392&edit=1

 ID:                 44392
 Updated by:         danack@php.net
 Reported by:        php at benjaminschulz dot com
 Summary:            getFilePointer() for Childs of SplFileObject
-Status:             Assigned
+Status:             Analyzed
 Type:               Feature/Change Request
 Package:            SPL related
 PHP Version:        5.3CVS-2008-03-10 (CVS)
 Assigned To:        danack
 Block user comment: N
 Private report:     N

 New Comment:

It might not be possible to implement this in anything close to a safe way. The code assumes that
the internal file resource isn't closed by anything outside of the SplFileObject, and has no
checks against whether the file resource is closed externally.

As there is no check, a segfault can occur if the file has been closed:

==13354== Process terminating with default action of signal 11 (SIGSEGV)
==13354==  Bad permissions for mapped region at address 0x0
==13354==    at 0x0: ???
==13354==    by 0x6A9DBC: _php_stream_fill_read_buffer (streams.c:675)
==13354==    by 0x6A9EE6: _php_stream_read (streams.c:722)
==13354==    by 0x606774: zim_spl_SplFileObject_fread (spl_directory.c:2932)


For the Curl use-case, you should be able to work around it, just by opening the file again
directly. 

curl_setopt($ch, CURLOPT_INFILE, fopen($splFileObject->getRealPath()));


Previous Comments:
------------------------------------------------------------------------
[2017-01-22 13:30:39] danack@php.net

I've created a PR for this based on Jordan's patch: https://github.com/php/php-src/pull/2328

------------------------------------------------------------------------
[2015-01-14 20:28:06] mattsch at gmail dot com

The Streamable interface sounds like a great idea.  Now is this bug ever going to get prioritized?

------------------------------------------------------------------------
[2014-05-13 14:50:45] nyamsprod at gmail dot com

Even thought making the SplFileObject::getFilePointer() method public would be a great addition I
think there is a better solution which would be to create a abstract interface "à la"
Traversable but called "Streamable". 
This interface would not be implemented alone but classes that implement it like SplFileObject would
be usable directly on function like stream_append_filter, streamp_get_metadata of even curl_setopt. 
That way the SplFileObject file pointer would be "usable" but its file pointer property
would remain protected from a developer who would otherwise use the SplFileObject::getFilePointer()
result direclty on a fclose function.

------------------------------------------------------------------------
[2013-12-04 13:05:20] drgomesp at gmail dot com

Any updates on this? It would be really useful to change the visibility of this method to public.

------------------------------------------------------------------------
[2012-12-12 16:12:02] mattsch at gmail dot com

I agree that this method should also be public.  Please implement this method ASAP.

------------------------------------------------------------------------


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=44392


--
Edit this bug report at https://bugs.php.net/bug.php?id=44392&edit=1


Thread (12 messages)

« previous php.bugs (#206859) next »