Skip to content

loader_app: Avoid abort on malformed Evergreen manifest - #13123

Merged
yuying-y merged 2 commits into
youtube:mainfrom
yuying-y:fix_eg_version_compare
Oct 20, 2026
Merged

yuying-y merged 2 commits into
youtube:mainfrom
yuying-y:fix_eg_version_compare

Conversation

@yuying-y

@yuying-y yuying-y commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • 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

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
@yuying-y
yuying-y requested a review from a team as a code owner October 6, 2026 00:05
@yuying-y
yuying-y requested a review from jellefoks October 6, 2026 00:05

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread starboard/loader_app/slot_management.cc Resolved
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ✅ PASS All checks passed
CI / android ✅ PASS Passed
CI / evergreen ✅ PASS Passed
CI / linux ✅ PASS Passed
CI / tvos ✅ PASS Passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


evergreen: Avoid abort on malformed manifest

CompareEvergreenVersion previously used std::stoi() to parse manifest
version strings. Since Cobalt builds with -fno-exceptions, std::stoi()
calls abort() when encountering malformed segments. This could lead to a
crash loop if a manifest in a writable slot becomes corrupted,
preventing the system-image fallback from running.

This change replaces std::stoi() with a custom validating parser that
safely handles non-numeric, empty, or overflowing segments. It also
updates ReadEvergreenVersion() to validate JSON types before access to
prevent aborts from jsoncpp, which is also built without exceptions.
Regression tests are added for various malformed manifest scenarios.

Bug: 545796318

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-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
@yuying-y
yuying-y enabled auto-merge (squash) October 19, 2026 23:21

@jellefoks jellefoks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice validation!

@yuying-y
yuying-y merged commit 50941a0 into youtube:main Oct 20, 2026
712 of 719 checks passed
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants