vectordotdev / vectordotdev/vector
`get_offset_reader_file_id` is incorrect in ledger.rs
Open
Beginner friendly
Nobody has claimed this yet.
domain: buffers
- Dominant language
- Rust
- Stars
- 22.6k
- Forks
- 2.3k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 146
Description
A note for the community
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Problem
Current impl:
fn get_offset_reader_file_id(&self, offset: u16) -> u16 {
self.get_current_reader_file_id().wrapping_add(offset) % MAX_FILE_ID
}
Consider:
current = 65534, offset = 1, returns 0
65534.wrapping_add(1) % 65535
65535 % 65535
0
current = 65534, offset = 2, still returns 0
65534.wrapping_add(2) % 65535
0 % 65535
0
One way to fix:
fn get_offset_reader_file_id(&self, offset: u16) -> u16 {
let curr = u32::from(self.get_current_reader_file_id());
let off = u32::from(offset);
u16::try_from((curr + off) % u32::from(MAX_FILE_ID))
.expect("(_ % MAX_FILE_ID) always fits in u16")
}
This is also a likely root-cause of #19759
Configuration
Version
latest (v0.55.0)
Debug Output
Example Data
No response
Additional Context
No response
References
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ledger.rs at get_offset_reader_file_id and compare its wrapping arithmetic with the 65534/1 and 65534/2 examples in the issue. Verify that offset file IDs wrap correctly below MAX_FILE_ID and add or run the relevant ledger tests if present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100