Repository navigation
loader_app: Avoid abort on malformed Evergreen manifest - #13123
Merged
Merged
Conversation
CompareEvergreenVersion() parsed each dot-separated segment of the manifest version string with std::stoi(). Cobalt builds with -fno-exceptions, so when std::stoi() hits a malformed segment (non-numeric, empty, or larger than INT_MAX) it calls abort(). The version comes from <storage>/installation_N/manifest.json and is parsed in LoadSlotManagedLibrary() before the retry/rollback loop. A corrupted manifest in a writable slot could therefore crash loader_app on every launch, and the system-image fallback never got a chance to run. This change: - Replaces std::stoi() with a validating parser that only accepts non-empty, all-digit segments that fit in an int, and stops at the first NUL in the fixed-size buffer. When a version is malformed, CompareEvergreenVersion() now logs a warning and returns 0, as the header already documents for invalid versions. This also removes an out-of-bounds read on empty vectors. - Hardens ReadEvergreenVersion() the same way. jsoncpp is built with JSON_USE_EXCEPTION=0, so isMember() on a non-object root (e.g. "[]") or asString() on an array/object "version" value would also abort. ReadEvergreenVersion() now checks the JSON types first. - Adds regression tests for malformed, overflowing, and non-NUL-terminated versions, and for malformed manifest JSON. Bug: 545796318 TAG=agy CONV=36d45fc7-2514-4e63-be66-4d452465dcf8
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of the loader application by validating JSON types in ReadEvergreenVersion and replacing std::stringstream/std::stoi with a custom ParseEvergreenVersion function to prevent crashes on malformed input when exceptions are disabled. Corresponding unit tests were also added to verify the handling of malformed manifests and version strings. The review feedback suggests checking for empty or NUL-started version vectors at the beginning of CompareEvergreenVersion to avoid flooding the logs with false-positive warnings during normal operations like first boot or factory reset.
Contributor
|
Contributor
🤖 Gemini Suggested Commit Message💡 Pro Tips for a Better Commit Message:
|
Address review feedback: an empty version is expected when a slot's manifest can't be read (e.g. first boot or after a factory reset), so return 0 early without logging a malformed-version warning. Bug: 545796318 TAG=agy CONV=36d45fc7-2514-4e63-be66-4d452465dcf8
briantting
pushed a commit
that referenced
this pull request
Oct 20, 2026
… manifest Refer to original PR: #13123 CompareEvergreenVersion() parsed each dot-separated segment of the manifest version string with std::stoi(). Cobalt builds with -fno-exceptions, so when std::stoi() hits a malformed segment (non-numeric, empty, or larger than INT_MAX) it calls abort(). The version comes from <storage>/installation_N/manifest.json and is parsed in LoadSlotManagedLibrary() before the retry/rollback loop. A corrupted manifest in a writable slot could therefore crash loader_app on every launch, and the system-image fallback never got a chance to run. This change: - Replaces std::stoi() with a validating parser that only accepts non-empty, all-digit segments that fit in an int, and stops at the first NUL in the fixed-size buffer. When a version is malformed, CompareEvergreenVersion() now logs a warning and returns 0, as the header already documents for invalid versions. This also removes an out-of-bounds read on empty vectors. - Hardens ReadEvergreenVersion() the same way. jsoncpp is built with JSON_USE_EXCEPTION=0, so isMember() on a non-object root (e.g. "[]") or asString() on an array/object "version" value would also abort. ReadEvergreenVersion() now checks the JSON types first. - Keeps the original silent behavior for empty versions (e.g. an empty slot on first boot): CompareEvergreenVersion() returns 0 early without logging. Only non-empty malformed versions log a warning. - Adds regression tests for malformed, overflowing, and non-NUL-terminated versions, and for malformed manifest JSON. Bug: 545796318 TAG=agy CONV=36d45fc7-2514-4e63-be66-4d452465dcf8 (cherry picked from commit 50941a0)
briantting
pushed a commit
that referenced
this pull request
Oct 20, 2026
… manifest Refer to original PR: #13123 CompareEvergreenVersion() parsed each dot-separated segment of the manifest version string with std::stoi(). Cobalt builds with -fno-exceptions, so when std::stoi() hits a malformed segment (non-numeric, empty, or larger than INT_MAX) it calls abort(). The version comes from <storage>/installation_N/manifest.json and is parsed in LoadSlotManagedLibrary() before the retry/rollback loop. A corrupted manifest in a writable slot could therefore crash loader_app on every launch, and the system-image fallback never got a chance to run. This change: - Replaces std::stoi() with a validating parser that only accepts non-empty, all-digit segments that fit in an int, and stops at the first NUL in the fixed-size buffer. When a version is malformed, CompareEvergreenVersion() now logs a warning and returns 0, as the header already documents for invalid versions. This also removes an out-of-bounds read on empty vectors. - Hardens ReadEvergreenVersion() the same way. jsoncpp is built with JSON_USE_EXCEPTION=0, so isMember() on a non-object root (e.g. "[]") or asString() on an array/object "version" value would also abort. ReadEvergreenVersion() now checks the JSON types first. - Keeps the original silent behavior for empty versions (e.g. an empty slot on first boot): CompareEvergreenVersion() returns 0 early without logging. Only non-empty malformed versions log a warning. - Adds regression tests for malformed, overflowing, and non-NUL-terminated versions, and for malformed manifest JSON. Bug: 545796318 TAG=agy CONV=36d45fc7-2514-4e63-be66-4d452465dcf8 (cherry picked from commit 50941a0)
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.
CompareEvergreenVersion() parsed each dot-separated segment of the manifest version string with std::stoi(). Cobalt builds with -fno-exceptions, so when std::stoi() hits a malformed segment (non-numeric, empty, or larger than INT_MAX) it calls abort(). The version comes from /installation_N/manifest.json and is parsed in LoadSlotManagedLibrary() before the retry/rollback loop. A corrupted manifest in a writable slot could therefore crash loader_app on every launch, and the system-image fallback never got a chance to run.
This change:
Bug: 545796318
TAG=agy
CONV=36d45fc7-2514-4e63-be66-4d452465dcf8