Skip to content

Commit

Permalink
liblzma: Always validate the first digit of a preset string
Browse files Browse the repository at this point in the history
lzma_str_to_filters() may call parse_lzma12_preset() in two ways. The
call from str_to_filters() detects the string type from the first
character(s) and as a side-effect it validates the first digit of
the preset string. So this change makes no difference there.

However, the call from parse_options() doesn't pre-validate the string.
parse_lzma12_preset() will return an invalid value which is passed to
lzma_lzma_preset() which safely rejects it. The bug still affects the
the error message:

    $ xz --filters=lzma2:preset=X
    xz: Error in --filters=FILTERS option:
    xz: lzma2:preset=X
    xz:               ^
    xz: Unsupported preset

After the fix:

    $ xz --filters=lzma2:preset=X
    xz: Error in --filters=FILTERS option:
    xz: lzma2:preset=X
    xz:              ^
    xz: Unsupported preset

The ^ now correctly points to the X and not past it because the X itself
is the problematic character.

Fixes: cedeeca
  • Loading branch information
Larhzu committed Jan 5, 2025
1 parent 52ff324 commit 7510721
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/liblzma/common/string_conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ parse_lzma12_preset(const char **const str, const char *str_end,
uint32_t *preset)
{
assert(*str < str_end);

if (!(**str >= '0' && **str <= '9'))
return "Unsupported preset";

*preset = (uint32_t)(**str - '0');

// NOTE: Remember to update LZMA12_PRESET_STR if this is modified!
Expand Down

0 comments on commit 7510721

Please # to comment.