maltzsama opened a new pull request, #177:
URL: https://github.com/apache/arrow-swift/pull/177

   ## 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 
`.failure` result instead of crashing with a fatal range error.
   
   ### Root Cause
   
   The `validateFileData()` function in `ArrowReaderHelper.swift` attempted to 
read the first and last 6 bytes of the input data without checking if the data 
was large enough. When `data.count < 6`, subscript operations like `data[..<6]` 
would fail with a range error, causing a crash.
   
   ### Changes Made
   
   1. Added a bounds check: `guard data.count >= markerLength * 2 else { return 
false }`
   2. Replaced direct subscripting with `prefix()` and `suffix()` for safer 
slice operations
   3. Added unit tests to verify the fix handles edge cases:
      - Empty files
      - Files smaller than marker size
      - Files with partial markers
   
   ### Testing
   
   - New test `testFromFileWithInvalidData()` added to `IPCFileReaderTests`
   - Test verifies that invalid files return `.failure` instead of crashing
   - All existing tests continue to pass
   
   ### Impact
   
   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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to