Skip to content

[FIX] Reject malformed --buffersize, --sendto and --service values - #2393

Merged
cfsmp3 merged 1 commit into
masterfrom
fix/reject-malformed-option-values
Oct 18, 2026
Merged

cfsmp3 merged 1 commit into
masterfrom
fix/reject-malformed-option-values

Conversation

@cfsmp3

@cfsmp3 cfsmp3 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

In raising this pull request, I confirm the following (please check boxes):

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

On master, with any input file:

  • ccextractor input.ts --buffersize abc (or 12x, 3G) runs with exit 0 — the value silently becomes 0 and is clamped to an 8-byte file buffer.
  • ccextractor input.ts --sendto 127.0.0.1:abc (or host:, [::1]:abc) aborts with SIGABRT (exit 134): panicked at src/parser.rs:1404.
  • ccextractor input.ts --service 99999999999999999999999 aborts with SIGABRT: panicked at src/parser.rs:363.

Same class as #2374/#2386: option values that were parsed after clap with a lenient helper or unwrap().

  • --buffersize: validated by clap — a byte count with an optional K/M/G suffix (as documented), fitting an int. Values below 8 are still clamped to 8. Replaces the lenient atol().
  • --sendto: validated by clap via the same split_sendto_address() used to assign the address and port (host, host:port, [ipv6], [ipv6]:port, as before).
  • --service: a service number too large for usize now gets the existing "Invalid service number" error instead of a panic.
Arguments master this PR
--buffersize=abc / 12x / empty exit 0, silent exit 1, invalid value …: expected a size in bytes, optionally suffixed with K, M or G
--buffersize=3G / 99999999999 exit 0, silent exit 1, size is too large
--sendto host:abc / host: / [::1]:abc SIGABRT exit 1, invalid port '…'
--service 99999999999999999999999 SIGABRT exit 7, Invalid service number (…)

Verified: new tests fail on the old behaviour and pass now (423 + 54); valid values parse identically (tests) and give byte-identical output end to end; --help is unchanged; fmt/clippy clean on 1.99.1; 14-run sample sweep identical to master.

--buffersize went through a lenient atol(): "abc", "12x" or an empty
value silently became 0, which is then clamped to an 8-byte file
buffer, and "3G" overflowed i32. It is now validated by clap: a byte
count with an optional K, M or G suffix, as documented, that fits in
an int.

--sendto parsed the port with unwrap(), so "host:abc", "host:" or an
out-of-range port aborted the process (SIGABRT). It is now validated
by clap through the same split used to assign the address and port.

--service parsed each service number with unwrap(), so a number too
large for usize aborted. It now reports the existing "Invalid service
number" error instead.

Valid values parse exactly as before; --help is unchanged.
@cfsmp3
cfsmp3 merged commit 0bf2a94 into master Oct 18, 2026
47 of 49 checks passed
@cfsmp3
cfsmp3 deleted the fix/reject-malformed-option-values branch October 18, 2026 04:50
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