Repository navigation
Validate NumStates and negative Start state in VectorFstImpl::Read. - #346
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
copybara/995035133
branch
3 times, most recently
from
October 7, 2026 15:20
5a29e1e to
39c97f6
Compare
…ad`. `VectorFstImpl::Read` previously passed `hdr.NumStates()` directly to `ReserveStates(size_t)` whenever `hdr.NumStates() != kNoStateId`, and only checked `impl->Start() >= state` after reading states. As a result: - A negative `hdr.NumStates()` other than `kNoStateId` (e.g., `-2`) converted to a huge `size_t` in `ReserveStates` and aborted, and a huge positive `hdr.NumStates()` in a corrupt or truncated header attempted an unbounded upfront allocation before reading the first state. - A negative start state `< kNoStateId` (e.g., `-2`) passed the `impl->Start() != kNoStateId && impl->Start() >= state` check. Reject `hdr.NumStates() < 0 || hdr.NumStates() > kMaxStates` (when `!= kNoStateId`), cap the upfront `ReserveStates` call to `kMaxReserveStates`, and reject `impl->Start() < 0` in the start-state range check (matching `ConstFstImpl::Read` and `CompactArcStore::Read`). Add unit tests in `fst_limits_test.cc`. PiperOrigin-RevId: 995131897
copybara-service
Bot
force-pushed
the
copybara/995035133
branch
from
October 7, 2026 15:40
39c97f6 to
d3b4480
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Validate
NumStatesand negativeStartstate inVectorFstImpl::Read.VectorFstImpl::Readpreviously passedhdr.NumStates()directly toReserveStates(size_t)wheneverhdr.NumStates() != kNoStateId, and only checkedimpl->Start() >= stateafter reading states. As a result:hdr.NumStates()other thankNoStateId(e.g.,-2) converted to a hugesize_tinReserveStatesand aborted, and a huge positivehdr.NumStates()in a corrupt or truncated header attempted an unbounded upfront allocation before reading the first state.< kNoStateId(e.g.,-2) passed theimpl->Start() != kNoStateId && impl->Start() >= statecheck.Reject
hdr.NumStates() < 0 || hdr.NumStates() > kMaxStates(when!= kNoStateId), cap the upfrontReserveStatescall tokMaxReserveStates, and rejectimpl->Start() < 0in the start-state range check (matchingConstFstImpl::ReadandCompactArcStore::Read). Add unit tests infst_limits_test.cc.