fix: Handle files shorter than the Arrow file marker#177
Open
maltzsama wants to merge 1 commit into
Open
Conversation
Member
|
@willtemperley Could you review this? |
willtemperley
approved these changes
Jul 25, 2026
willtemperley
left a comment
Contributor
There was a problem hiding this comment.
Looks like an improvement in general. I think ideally testing for degenerate cases like this would be done against the fuzz regression files [1] too but that's a fair amount of work.
Member
|
OK. Let's work on it as a separated task.
|
Added bounds check in validateFileData() to prevent crash when processing files smaller than the Arrow file marker size (6 bytes). The function now returns false gracefully instead of panicking. - Added guard clause to check minimum file size - Replaced unsafe subscripting with prefix()/suffix() - Added unit test testFromFileWithInvalidData() covering edge cases Closes apache#176
maltzsama
force-pushed
the
fix/validatefiledata
branch
from
July 25, 2026 13:53
5b21592 to
d81084e
Compare
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.
What's Changed
Fixed a crash in
ArrowReader.fromFile()when processing files smaller than the Arrow file marker size (6 bytes). The function now gracefully returns a.failureresult instead of crashing with a fatal range error.Root Cause
The
validateFileData()function inArrowReaderHelper.swiftattempted to read the first and last 6 bytes of the input data without checking if the data was large enough. Whendata.count < 6, subscript operations likedata[..<6]would fail with a range error, causing a crash.Changes Made
guard data.count >= markerLength * 2 else { return false }prefix()andsuffix()for safer slice operationsTesting
testFromFileWithInvalidData()added toIPCFileReaderTests.failureinstead of crashingImpact
This fix improves robustness for applications using
ArrowReader.fromFile()with user-supplied or untrusted files, preventing denial of service from truncated or malformed input.Closes #176