Repository navigation
Return pos 0 instead of aborting when IFields data is truncated - #1050
Merged
copybara-service[bot] merged 1 commit intoOct 7, 2026
Merged
Conversation
ReadVisitor::operator()(IFields&) pushes onto end_, but the branch for `pos + num_u32 > span.size()` returned without popping. ~ReadVisitor then failed HWY_ASSERT(end_.empty()), so reading a truncated or corrupt config or MatPtr aborted instead of returning ReadResult.pos == 0 as documented in fields.h. Callers such as model_store.cc never got to print their "Error deserializing config" diagnostics. Pop end_ in that branch, as the SkipField branch above already does, and add a test that reads a span shorter than the stored size.
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.
Fixes #1048
What / why
ReadVisitor::operator()(IFields&)inio/fields.ccpushes ontoend_, but it returns without popping whenpos + num_u32 > span.size(). As a result,~ReadVisitorfailsHWY_ASSERT(end_.empty())and the process aborts.ReadResultinio/fields.hsays this case should returnpos == 0instead ("the span is shorter than the data says it should be"). Because of the abort, themodel_store.ccdiagnostics for corrupt configs andMatPtrblobs ("Error deserializing config", "Deserializing MatPtr %s failed") are never printed.This PR pops
end_in that branch, the same way theSkipField()branch just above does. It also addsFieldsTest.TestTruncatedData, which reads a span that is shorter than the stored size and expectspos == 0.Callers that already abort on
pos == 0behave the same as before, except that they now print their own error message.Testing
io/fields.ccfromdev@ 0224dcb): aborts with SIGABRT (exit code 134).[ PASSED ] 10 tests.blob_store_test: 2/2 passed.gemma/configs_test.ccis Bazel-only; built separately against the CMake build, it passes 9/9.clang-format(repo.clang-format) reports no changes toio/fields.ccor to the new test.Environment: macOS 26.5, Apple M4, Apple clang 17.0.0, CMake 4.4.3.