Skip to content

fix: leftover packing-tool CLI stoi - #1

Open
tonycoder-hub wants to merge 1 commit into
openharmony:masterfrom
tonycoder-hub:leftover-packing-cli-stoi
Open

fix: leftover packing-tool CLI stoi#1
tonycoder-hub wants to merge 1 commit into
openharmony:masterfrom
tonycoder-hub:leftover-packing-cli-stoi

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Problem

app_packing_tool parses untrusted CLI integers with std::stoi:

  • Utils::IsPositiveInteger (version-code / API version validation)
  • --compress-level
  • --atomic-service-entry-size-limit / --atomic-service-non-entry-size-limit
  • version-normalize / general-normalize CLI version and API params

std::stoi throws on overflow and can accept partial tokens when callers skip digit prechecks. Empty / junk input is not rejected uniformly.

Fix

Add ParsePackingInt32 (std::from_chars) in packing_tool/frameworks/include/parse_packing_int.h.

  • Whole-token parse: reject empty, overflow, underflow, leading/trailing junk, + prefix, hex, and floats.
  • Valid in-range values keep the same numeric result as before ("0" / "5" / "2048" / "4194304" / leading zeros / INT_MAX / INT_MIN).
  • On failure, log via existing packing-tool error paths and reject the CLI value.

Test

Host + ASan/UBSan verification of ParsePackingInt32 (kept out of this PR):

  • valid: 0 / 1 / 5 / 9 / 2048 / 4194304 / leading zeros / INT_MAX / INT_MIN / -1
  • reject: empty, overflow, underflow, huge digits, trailing junk 1abc, spaces, +, hex, float, newline

All cases passed with -fsanitize=address,undefined.

Signed-off-by: Tony Coder 407243179@qq.com

packing-tool parses untrusted CLI integers (version-code, compress-level,
atomic-service size limits, general/version-normalize params) with
std::stoi. Overflow throws; partial/junk tokens can still be accepted
when callers skip digit prechecks. Parse with std::from_chars via
ParsePackingInt32 so valid in-range values stay unchanged and
overflow/partial/empty/junk is rejected and logged.

Signed-off-by: Tony Coder <407243179@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant