fix: Guard against force unwraps on malformed ArrowReader input#183
Open
maltzsama wants to merge 6 commits into
Open
fix: Guard against force unwraps on malformed ArrowReader input#183maltzsama wants to merge 6 commits into
maltzsama wants to merge 6 commits into
Conversation
Replace force unwrapping with proper guard statements to prevent crashes when parsing malformed Arrow files without a schema or RecordBatch header.
Replace force unwraps with guard statements when accessing footer schema and RecordBatch messages to prevent crashes on malformed Arrow files.
…sages Replace force unwraps with guard statements when parsing Message headers to prevent crashes on malformed Arrow streams.
Adds a test that verifies readStreaming fails gracefully when a RecordBatch message appears without a preceding Schema message, instead of crashing.
Replace relative offset slicing with startIndex-based indexing to ensure correct data boundaries when parsing streaming Arrow messages.
Member
|
@willtemperley Could you review this? |
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
readStreaming,readFile, andfromMessageforce-unwrapped optional schema and message header values, causing crashes on malformed or out-of-order input instead of returning anArrowError. For example, a RecordBatch message arriving with no preceding Schema message would crash the process rather than fail gracefully.Replaced the force unwraps with guard statements that return
.failureinstead:readStreaming: guards on the RecordBatch header,schemaMessage, andresult.schemabefore usereadFile: guards onfooter.schema, the RecordBatch header, andresult.schemabefore usefromMessage: guards on the Schema header, the RecordBatch header,result.messageSchema, andresult.schemabefore useWhile writing a regression test for the above, found that
readStreamingalso assumed zero-basedDataindices internally. Slicing aData(data[offset...]) preserves the original absolute indices rather than resetting to zero, so a caller passing a slice — rather than a freshly allocatedData— could desync the reader's internal offset tracking and crash on a completely valid, well-formed input. Fixed by offsetting frominput.startIndexinstead of assuming 0.Testing
Added a regression test (
testReadStreamingRecordBatchBeforeSchema) that builds a valid streaming payload, strips the Schema message via slicing, and confirmsreadStreamingnow returns.failureinstead of crashing. This test only passes with both fixes in place — reverting either one reproduces a crash.Full test suite passes (48 tests, 0 failures).
Closes #182