Skip to content

Conversation

@THE-Amrit-mahto-05
Copy link
Contributor

@THE-Amrit-mahto-05 THE-Amrit-mahto-05 commented Jan 18, 2026

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

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Description

payload_type and payload_size were previously inferred or explicitly defined as i32, which required repeated casting when indexing buffers or comparing against slice lengths. This added unnecessary casts and could theoretically lead to incorrect behavior for large payload values.

Fix

  • Changed payload_type and payload_size to explicit usize.
  • Removed unnecessary as i32 casts during accumulation.
  • Removed redundant as usize casts during indexing and bounds checks.
  • Ensured seibuf_idx arithmetic remains type-safe and consistent.

Copy link
Contributor

@cfsmp3 cfsmp3 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! The intent to clean up the type handling is good, but the implementation uses the wrong type.

Issue: usize is platform-dependent

usize varies by platform (32-bit on 32-bit systems, 64-bit on 64-bit systems). Our coding guidelines require fixed-width types for data values:

Use fixed-width types (int64_t, uint32_t) over platform-dependent types (size_t, long)

Recommended fix

Use u32 instead of usize:

let mut payload_type: u32 = 0;
// ...
payload_type += seibuf[seibuf_idx] as u32;

let mut payload_size: u32 = 0;
// ...
payload_size += seibuf[seibuf_idx] as u32;

Keep the as usize casts where needed for indexing/slicing - those are correct and explicit:

seibuf_idx += payload_size as usize;
// ...
if !broken && payload_type == 4 && payload_start + payload_size as usize <= seibuf.len() {
    let payload_data = &seibuf[payload_start..payload_start + payload_size as usize];

Why this matters

  • payload_type is never used for indexing - it's only compared against constants and printed. u32 works directly.
  • payload_size needs usize only for indexing operations, and the cast is cheap (just a register widen on 64-bit).
  • The original i32 was close to correct - it just used signed when unsigned is more appropriate. The fix should be i32u32, not i32usize.

The goal of removing casts is less important than using the correct fixed-width type.

@THE-Amrit-mahto-05
Copy link
Contributor Author

@cfsmp3
Thanks
I’ve updated followings:
Changed payload_type and payload_size to u32
Kept explicit as usize casts only where required for indexing and slicing.
Left the logic unchanged, focusing purely on type correctness

@THE-Amrit-mahto-05
Copy link
Contributor Author

@cfsmp3
Some Rust tests are already failing on master. Since my change only adjusts type correctness (i32 → u32) without altering logic or control flow, it shouldn’t affect test behavior.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit d494286...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 6/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 85/86
Teletext 21/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit d494286...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 6/7
DVD 3/3
DVR-MS 2/2
General 25/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 81/86
Teletext 21/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65...
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b...
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...

Congratulations: Merging this PR would fix the following tests:


It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

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.

3 participants