-
Notifications
You must be signed in to change notification settings - Fork 512
Fix buffer truncation warnings in EPG time strings #1910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix buffer truncation warnings in EPG time strings #1910
Conversation
Increased buffer size from 21 to 32 bytes for start_time_string and end_time_string to prevent potential truncation with large year values in snprintf formatting. Fixes compiler warnings in ts_tables_epg.c lines 130, 150, 181
cfsmp3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! However, after testing locally, the warnings are still present:
Master: 3 warnings
This PR: Still 3 warnings
The compiler calculates that snprintf output could be up to 73 bytes, but the buffer is only 32 bytes. The issue is that the format string allows unbounded year values.
To properly fix this, you could either:
- Increase buffer size to 80 bytes (to safely accommodate all theoretical values)
- Validate/bound the year values before formatting
- If these warnings are false positives (years will never be that large in practice), consider suppressing them with a pragma
Could you update the fix to fully eliminate the warnings?
Per @cfsmp3's feedback, 32 bytes was insufficient. Compiler calculates snprintf could need up to 73 bytes in worst case. Using 80 bytes ensures all theoretical values are safely accommodated.
@cfsmp3 Thank you for testing and the detailed feedback! You're absolutely right. I've updated the buffer size to 80 bytes to fully accommodate the compiler's calculated maximum of 73 bytes. This should completely eliminate all three warnings. The updated commit increases both Ready for another review when you have time. Thanks again for the guidance! |
cfsmp3
left a comment
There was a problem hiding this 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 struct field size increase is correct, but the fix is incomplete.
The warning still appears because EPG_ATSC_calc_time() at line 130 still uses a hardcoded 21:
snprintf(output, 21, "%02d%02d%02d%02d%02d%02d +0000", ...);To fully fix this, you need to either:
-
Add a size parameter to the function (preferred):
void EPG_ATSC_calc_time(char *output, size_t output_size, uint32_t time) { // ... snprintf(output, output_size, ...); }
Then update the callers to pass
sizeof(event.start_time_string). -
Or define a constant and use it in both places:
#define EPG_TIME_STRING_SIZE 80
Please update the PR to eliminate the warning completely. Thanks!
@cfsmp3 Fixed! Added size parameter to EPG_ATSC_calc_time() and updated both callers to pass sizeof(). Changes made:
Tested locally with ./build in WSL: Thanks for the explanation and guidance through the fix! |
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 64ce4ac...:
Your PR breaks these cases:
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 CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 64ce4ac...:
Congratulations: Merging this PR would fix the following tests:
All tests passed completely. Check the result page for more info. |
Summary
Fixed buffer size for EPG time string buffers to prevent truncation warnings.
Changes
start_time_stringandend_time_stringbuffer size from 21 to 32 bytes ints_functions.hRationale
The compiler warned that
snprintfformatting ints_tables_epg.ccould truncate with large year values (e.g., 5+ digit years). While unlikely in practice, this fix ensures safety and eliminates three compiler warnings at lines 130, 150, and 181.Testing
ts_tables_epg.cWarnings Fixed