[PR #2034] [MERGED] Fix atol Parsing Bug in parser.rs for Numeric Values and Suffixes #2839

Closed
opened 2026-01-29 17:24:10 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/2034
Author: @THE-Amrit-mahto-05
Created: 1/18/2026
Status: Merged
Merged: 1/18/2026
Merged by: @cfsmp3

Base: masterHead: fix/parser-atol-bug


📝 Commits (2)

  • b2e9cb7 Fix atol parsing bug for numeric values and K/M/G suffixes
  • ead0a4b little fix

📊 Changes

1 file changed (+18 additions, -11 deletions)

View changed files

📝 src/rust/src/parser.rs (+18 -11)

📄 Description

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

the atol function does not correctly handle numeric buffer sizes in strings.

Current behavior

  • The function assumes the input always has a suffix (like K or M) and blindly drops the last character.
  • For strings like "100", it incorrectly parses the value as 10.
  • It can also panic on empty strings or short inputs.

Fix implemented

  • Trim the input string to remove whitespace.
  • If the string is empty, return 0.
  • Check if the last character is a digit
    • If yes, parse the whole string as an integer.
    • If no, treat it as a suffix (K, M, G) and multiply the numeric prefix accordingly
  • Safely ignores unknown suffixes without panicking.

Example behavior after fix

"100" → 100
"1K" → 1024
"1M" → 1048576
"1G" → 1073741824

This ensures that buffer sizes in the code are parsed correctly and prevents runtime errors or incorrect calculations, following the expected behavior of the original C implementation of atol.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/2034 **Author:** [@THE-Amrit-mahto-05](https://github.com/THE-Amrit-mahto-05) **Created:** 1/18/2026 **Status:** ✅ Merged **Merged:** 1/18/2026 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/parser-atol-bug` --- ### 📝 Commits (2) - [`b2e9cb7`](https://github.com/CCExtractor/ccextractor/commit/b2e9cb74c1845ed86c0d37ac76bbf621ac216d69) Fix atol parsing bug for numeric values and K/M/G suffixes - [`ead0a4b`](https://github.com/CCExtractor/ccextractor/commit/ead0a4beed8bb9b0d087ec979353b9d0832ac86b) little fix ### 📊 Changes **1 file changed** (+18 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `src/rust/src/parser.rs` (+18 -11) </details> ### 📄 Description <!-- Please prefix your pull request with one of the following: **[FEATURE]** **[FIX]** **[IMPROVEMENT]**. --> **In raising this pull request, I confirm the following (please check boxes):** - [x] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [x] I have checked that another pull request for this purpose does not exist. - [x] I have considered, and confirmed that this submission will be valuable to others. - [x] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [x] I give this submission freely, and claim no ownership to its content. - [x] **I have mentioned this change in the [changelog](https://github.com/CCExtractor/ccextractor/blob/master/docs/CHANGES.TXT).** **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. - [x] I am an active contributor to CCExtractor. --- ### Description the atol function does not correctly handle numeric buffer sizes in strings. ### Current behavior - The function assumes the input always has a suffix (like K or M) and blindly drops the last character. - For strings like "100", it incorrectly parses the value as 10. - It can also panic on empty strings or short inputs. ### Fix implemented - Trim the input string to remove whitespace. - If the string is empty, return 0. - Check if the last character is a digit - If yes, parse the whole string as an integer. - If no, treat it as a suffix (K, M, G) and multiply the numeric prefix accordingly - Safely ignores unknown suffixes without panicking. #### Example behavior after fix "100" → 100 "1K" → 1024 "1M" → 1048576 "1G" → 1073741824 This ensures that buffer sizes in the code are parsed correctly and prevents runtime errors or incorrect calculations, following the expected behavior of the original C implementation of atol. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:24:10 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2839