Doing
printf 0123456789 | cargo r -- head --bytes=0K
gives
But it should instead print nothing.
It seems the code passes 0K through the function below, removes every initial 0, turning 0K into bare K.
|
pub fn parse_signed_num_max(src: &str) -> Result<SignedNum, ParseSizeError> { |
|
let (sign, size_string) = strip_sign_prefix(src); |
|
|
|
// Empty string after stripping sign is an error |
|
if size_string.is_empty() { |
|
return Err(ParseSizeError::ParseFailure(src.to_string())); |
|
} |
|
|
|
// Remove leading zeros so size is interpreted as decimal, not octal |
|
let trimmed = size_string.trim_start_matches('0'); |
|
let value = if trimmed.is_empty() { |
|
// All zeros (e.g., "000" or "0") |
|
0 |
|
} else { |
|
parse_size_u64_max(trimmed)? |
|
}; |
|
|
|
Ok(SignedNum { value, sign }) |
|
} |
Then, the bare K is interpreted as 1K.
The fix can simply be to check if any zeros were removed before interpreting K to 1K.
Doing
gives
But it should instead print nothing.
It seems the code passes
0Kthrough the function below, removes every initial0, turning0Kinto bareK.coreutils/src/uucore/src/lib/features/parser/parse_signed_num.rs
Lines 77 to 95 in 0c8a3c7
Then, the bare
Kis interpreted as 1K.The fix can simply be to check if any zeros were removed before interpreting
Kto1K.