Skip to content

Fix GH-16217: guard uninitialized SplFileObject in fputcsv() and next() - #22454

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-16217-splfileobject-uninitialized
Closed

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-16217-splfileobject-uninitialized

Conversation

@iliaal

@iliaal iliaal commented Jun 25, 2026

Copy link
Copy Markdown
Member

SplFileObject::fputcsv() and ::next() were the only two SplFileObject methods reaching the file stream without the CHECK_SPL_FILE_OBJECT_IS_INITIALIZED backstop the others carry. On an object built via newInstanceWithoutConstructor() the constructor never runs and the stream stays NULL; calling either through reflection (which bypasses the get_method init check) segfaults. next() only reaches the stream when READ_AHEAD is set, itself reachable via the unguarded setFlags(). Both now throw Error: "Object not initialized".

Fixes #16217

…ext()

fputcsv() and next() reached the file stream without the
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED guard their siblings carry, so
invoking them via reflection on an object from
newInstanceWithoutConstructor() (constructor bypassed, stream NULL)
crashed instead of throwing. next() only touches the stream with the
READ_AHEAD flag, itself settable through the equally unguarded
setFlags(). Both now throw "Object not initialized".

Fixes phpGH-16217

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@iliaal iliaal closed this in 60d8e92 Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants