Repository navigation
Conversation
parse_708_services() took the charset of "all[X]" by slicing the value from byte 4 to one before the end whenever it was longer than "all". It never checked for the brackets, so: - "all1" and "all[" panicked (the range starts at 4 but ends at 3), and "allé" panicked slicing inside a character. The panic can't unwind out of ccxr_parse_parameters, so the process aborted (SIGABRT, exit 134). - "all[EUC-KR" lost its last letter and failed later in iconv with charset "EUC-K"; "allEUC-KR]" became "UC-KR". This came with the Rust parser (CCExtractor#1619). The C parser only took a charset when the value was longer than "all[]", so it never panicked, though it did not check the brackets either. Accept "all" and "all[charset]" only, and report anything else as a malformed parameter (exit 7), as CCExtractor#2393 does for service numbers.
Contributor
Author
|
@cfsmp3 A simple way to picture this bug, since it follows on from #2393: The old line
The fix checks that the value really is |
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.
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Problem
--servicepicks which CEA-708 services to extract. Besides service numbers (1,2), it acceptsallandall[charset](e.g.all[EUC-KR], as--helpdocuments). A small typo in theallform crashes ccextractor instead of reporting an error:--service all1,--service all[and--service allépanic. The panic can't unwind out ofccxr_parse_parameters(extern "C"), so the process aborts with SIGABRT (exit 134).--service all[EUC-KR(missing]) doesn't crash, but loses the last letter of the charset and fails later with a confusing iconv error about"EUC-K".allEUC-KR]becomes"UC-KR".#2393 fixed the same kind of abort for service numbers (
--service 99999999999999999999). This is theallbranch of the same function, which that PR didn't touch.Regression
This came with the Rust argument parser (#1619, first released in v0.96). The C
parse_708_services()it replaced only took a charset when the value was longer thanall[](s_len > all_len + 2), so it never crashed. The Rust port changed the guard tos.len() > 3and kept the slice:This skips 4 bytes (
all[) and drops the last one (]) without checking that either bracket is there. For a 4-byte value likeall1, the slice is&s[4..3]: the start is past the end, and Rust panics. Forallé, byte 4 is inside the 2-byteé, which also panics.Fix
A small helper,
all_services_charset(), returns the charset only for the two documented forms:""forallandXforall[X]. Anything else that starts withallis reported as a malformed parameter (exit 7), with the same wording and exit code that--servicealready uses for bad service numbers:Valid values parse exactly as before.
Repro
Sample:
VH1.ts, an ATSC MPEG transport stream with CEA-608 captions (212,140,032 bytes, sha256f9879aff48295d8ef9055289521ff8162e671a7a10eeac931fd4b3570fabb96a). The crash happens while the arguments are parsed, before the input is read, so any input file shows it.On master (d7eb132):
With this PR:
Testing
Built master (d7eb132) and this branch with
mac/build.commandand ran both onVH1.ts.Malformed values:
--serviceall1all[alléall[EUC-KRcan't create iconv for charset "EUC-K", exit 1allEUC-KR]can't create iconv for charset "UC-KR", exit 1Valid values, unchanged:
all,all[EUC-KR],all[]and1exit 0 on both builds, with identical output and identical logs (ignoring build info and processing time). The CEA-708 settings both builds print match, e.g.[CEA-708: 63 decoders active]and[CEA-708: using charset "EUC-KR" for all services]forall[EUC-KR].--service 0still givesInvalid service number (0), valid range is 1-63.(exit 7) on both. The sample carries only CEA-608, so these runs compare the parsed settings and logs rather than CEA-708 subtitle files.test_all_services_charset: acceptsall,all[EUC-KR]andall[], and rejectsall1,all[,allé,all[EUC-KRandallEUC-KR]. The existing--servicetests (all,all[EUC-KR], numbers, per-service charsets) still pass.cargo test: 427 passed.cargo fmt --checkandcargo clippyare clean.