apache / apache/arrow-swift

ArrowReader.fromFile crashes on files smaller than the Arrow file marker

Open Beginner friendly
#176 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
32
Forks
18
Avg merge
19h 14m
Merged PRs (30d)
2

Description

### Describe the bug, including details regarding any error messages, version, and platform.

### Description

`ArrowReader.fromFile()` crashes with a fatal error when processing files smaller than the Arrow file marker size (6 bytes), instead of returning a `.failure` result.

### Root Cause

The `validateFileData()` function in `ArrowReaderHelper.swift` attempts to read the first and last 6 bytes of the input data without first checking if the data is large enough:

```swift
func validateFileData(_ data: Data) -> Bool {
let markerLength = FILEMARKER.utf8.count
let startString = String(decoding: data[.. Bool {
let markerLength = FILEMARKER.utf8.count
guard data.count >= markerLength * 2 else { return false }
let startString = String(decoding: data.prefix(markerLength), as: UTF8.self)
let endString = String(decoding: data.suffix(markerLength), as: UTF8.self)
return startString == FILEMARKER && endString == FILEMARKER
}
```

Contributor guide

Open the contributing guide

Research direction

Start in ArrowReaderHelper.swift at validateFileData(), then trace how ArrowReader.fromFile() handles its result. Reproduce the issue with empty and shorter-than-marker files. Done means truncated or undersized input returns a failure result rather than crashing, with coverage for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-engineering
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.