Skip to content

fix: Guard against force unwraps on malformed ArrowReader input#183

Open
maltzsama wants to merge 6 commits into
apache:mainfrom
maltzsama:fix/arrowreader-force-unwraps
Open

fix: Guard against force unwraps on malformed ArrowReader input#183
maltzsama wants to merge 6 commits into
apache:mainfrom
maltzsama:fix/arrowreader-force-unwraps

Conversation

@maltzsama

@maltzsama maltzsama commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

What's Changed

readStreaming, readFile, and fromMessage force-unwrapped optional schema and message header values, causing crashes on malformed or out-of-order input instead of returning an ArrowError. 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 .failure instead:

  • readStreaming: guards on the RecordBatch header, schemaMessage, and result.schema before use
  • readFile: guards on footer.schema, the RecordBatch header, and result.schema before use
  • fromMessage: guards on the Schema header, the RecordBatch header, result.messageSchema, and result.schema before use

While writing a regression test for the above, found that readStreaming also assumed zero-based Data indices internally. Slicing a Data (data[offset...]) preserves the original absolute indices rather than resetting to zero, so a caller passing a slice — rather than a freshly allocated Data — could desync the reader's internal offset tracking and crash on a completely valid, well-formed input. Fixed by offsetting from input.startIndex instead of assuming 0.

Testing

Added a regression test (testReadStreamingRecordBatchBeforeSchema) that builds a valid streaming payload, strips the Schema message via slicing, and confirms readStreaming now returns .failure instead 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

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.
@kou

kou commented Jul 25, 2026

Copy link
Copy Markdown
Member

@willtemperley Could you review this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrowReader crashes on malformed input due to force unwraps

2 participants