fix(spec): accept Java's long memory-size units and reject overflow - #621
Open
jackylee-ch wants to merge 1 commit into
Open
fix(spec): accept Java's long memory-size units and reject overflow#621jackylee-ch wants to merge 1 commit into
jackylee-ch wants to merge 1 commit into
Conversation
`parse_memory_size` only recognized short unit spellings, so a valid Java option value such as `target-file-size = '256 mebibytes'` was silently dropped and the caller fell back to its default. It also multiplied unchecked: `'9007199254740993 kb'` wrapped to a negative size in a release build and panicked in a debug build. Accept every alias in Java `MemorySize.MemoryUnit` (`bytes`, `kibibytes`, `mebibytes`, `gibibytes`, `tebibytes` alongside the short forms) and use `checked_mul`, so an overflowing value returns `None` and the caller falls back to its default instead of wrapping.
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.
parse_memory_sizeonly recognized short unit spellings, so a valid Java optionvalue such as
target-file-size = '256 mebibytes'parsed asNoneand the callersilently fell back to its default. It also multiplied unchecked:
'9007199254740993 kb'wraps to a negative size in a release build and panics ina debug build.
Fix: accept every alias in Java
MemorySize.MemoryUnit(bytes,kibibytes,mebibytes,gibibytes,tebibytesalongside the short forms), and usechecked_mulso an overflowing value returnsNone— the callers then fall backto their default, which is what Java's thrown "numeric overflow" leads to as well.