Skip to content

XMLParser: fix premature stream termination on empty mid-stream reads#16

Merged
macbre merged 1 commit into
masterfrom
fix/issue-13-premature-stream-termination
Jun 11, 2026
Merged

XMLParser: fix premature stream termination on empty mid-stream reads#16
macbre merged 1 commit into
masterfrom
fix/issue-13-premature-stream-termination

Conversation

@macbre

@macbre macbre commented Jun 11, 2026

Copy link
Copy Markdown
Member

stream_get_contents() returns '' (empty string) at EOF, not false, so the previous $isFinal = ($data === false) check never triggered, and an empty read caused the nodesQueue to stay empty and valid() to return false — silently stopping iteration mid-document.

Compressed or network streams (e.g. compress.zlib:// over HTTP) can also return '' between internal block boundaries (zlib flush markers, TCP chunk boundaries) without being at EOF. The fix wraps the read loop so parseNextChunk() keeps reading until either at least one node is queued or feof() confirms the stream is truly exhausted, and a streamFinished flag prevents calling xml_parse() on an already-finalised parser.

Resolves #13.

stream_get_contents() returns '' (empty string) at EOF, not false, so the
previous $isFinal = ($data === false) check never triggered, and an empty
read caused the nodesQueue to stay empty and valid() to return false —
silently stopping iteration mid-document.

Compressed or network streams (e.g. compress.zlib:// over HTTP) can also
return '' between internal block boundaries (zlib flush markers, TCP chunk
boundaries) without being at EOF. The fix wraps the read loop so
parseNextChunk() keeps reading until either at least one node is queued or
feof() confirms the stream is truly exhausted, and a streamFinished flag
prevents calling xml_parse() on an already-finalised parser.

Fixes #13

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@macbre macbre self-assigned this Jun 11, 2026
@macbre macbre added the bug Something isn't working label Jun 11, 2026
@macbre macbre merged commit 4be0519 into master Jun 11, 2026
5 checks passed
@macbre macbre deleted the fix/issue-13-premature-stream-termination branch June 11, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser suddenly quits while parsing Discogs dump

1 participant