]> git.ipfire.org Git - thirdparty/xz.git/commit
liblzma: Always validate the first digit of a preset string
authorLasse Collin <lasse.collin@tukaani.org>
Sun, 5 Jan 2025 10:10:05 +0000 (12:10 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 5 Jan 2025 10:58:46 +0000 (12:58 +0200)
commit8eaf2cb58e56e6ae19e9c4542d23a33f4d7636ec
tree7bd8a612273512a26dabb7e74902a0c8893bd26d
parent9b5a5c39f43b7f949930f3b14d80285305f5aa16
liblzma: Always validate the first digit of a preset string

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: cedeeca2ea6ada5b0411b2ae10d7a859e837f203
(cherry picked from commit 75107217670a97b7b772833669d88c3c2f188e37)
src/liblzma/common/string_conversion.c