fix: StreamedBinaryFileResponse — Incorrect Chunking Logic#121
Merged
Conversation
Collaborator
Author
|
Review of this PR completed via coder-model (Qwen Code /review): This PR is a clean, correct simplification of the chunking logic in Deterministic checks: PHPStan ✅ | php-cs-fixer ✅ | Rector ✅ | PHPUnit (261 tests) ✅ Why each change is correct:
LGTM ✅ Ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes incorrect chunking logic in
StreamedBinaryFileResponseby simplifying the inner while loop that was unnecessarily complex and had a bug where$lengthwas decremented by$readinstead of actual data length.Changes
src/Protocol/Http/Response/StreamedBinaryFileResponse.php:36-52while ('' !== $data)loop that only executed once in most casesstrlen($data)instead of$readbecausefread()may return fewer bytes than requested$data === '') alongside the existingfalsecheck for more robust handlingbreak 2to singlebreaksince we're now only using one loop levelWhy
The original code had two issues:
substr($data, $read)when$read >= strlen($data)returns empty string, causing the loop to execute exactly once$length -= $readwas incorrect - should use actual data length sincefread()can return fewer bytes than requestedTesting
Closes #27