Skip to content
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

Fix MD_S8ChopWhitespace underflow and infinite loop #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dbechrd
Copy link

@dbechrd dbechrd commented Sep 14, 2023

MD_S8ChopWhitespace has two obvious bugs:

  1. MD_u64 i = string.size-1 can underflow when string.size is 0.
  2. i < string.size is the wrong condition to check for a loop that starts at the end of the string.

Theoretically, this PR fixes both issues, but haven't tested this code at all, so you may want to test it on your side or just fix the loop yourself in whatever way you see fit. :)

The code I wrote is a bit contrived, but I looped forward instead of backward to avoid the decrement at zero problem that would've required us to replace MD_u64 with a signed type. This preserves the upper half of the unsigned range in the extraordinarly unlikely case that someone has a string that large (maybe's it's a virtual string? lol).

`MD_S8ChopWhitespace` has two obvious bugs.

1) `MD_u64 i = string.size-1` can underflow when string.size is 0.
2) `i < string.size` is the wrong condition to check for a loop that starts at the end of the string.

I "fixed" the loop in this PR, but haven't tested this code at all, so you may want to test it on your side or just fix the loop yourself in whatever way you see fit. :)
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