[datalog] Reject oversized Java data log records - #9313
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e61bf5115
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| int getNextRecord(int pos) { | ||
| return getRecordInfo(pos).nextPos; |
There was a problem hiding this comment.
Avoid materializing discarded records while advancing
When clients use the standard hasNext()/next() iteration pattern, hasNext() calls getRecordInfo() once and next() calls it twice more—through both getRecord() and this method. Each log record is therefore parsed three times, with two temporary DataLogRecord, RecordInfo, and ByteBuffer views discarded; large wpilog files will incur avoidable CPU, allocation, and GC overhead compared with the previous constant-time hasNext() and lightweight advancement. Cache the parsed record in the iterator or separate bounds validation/position calculation from record materialization.
Useful? React with 👍 / 👎.
The wpilog record size is an unsigned value of up to four bytes, but Java casts
readVarInt()directly to signedint(DataLogReader.java:115-129) andreconstructs it in another signed
intingetNextRecord()(
DataLogReader.java:135-146). The iterator then trusts that result as its nextoffset (
DataLogIterator.java:19-41) without requiring forward progress.For a seven-byte record header, encoded size
0xfffffff9becomes-7.ByteBuffer.limit()reduces the duplicate's position and yields an empty dataslice, while
pos + headerLen + sizeequals the originalpos. The record isaccepted forever at the same offset.