Skip to content

lzma._decode_filter_properties crashes with BCJ filter and buffer of zero length #104282

Closed
@chgnrdv

Description

@chgnrdv

Example:

>>> import lzma
>>> lzma._decode_filter_properties(lzma.FILTER_X86, b"")
Segmentation fault (core dumped)

In _lzma__decode_filter_properties_impl call to lzma_properties_decode returns LZMA_OK and leaves filter.options intact (that is uninitialized) if filter.id is id of a BCJ filter (FILTER_X86, FILTER_POWERPC, FILTER_IA64, FILTER_ARM, FILTER_ARMTHUMB, FILTER_SPARC) and encoded_props->len is equal to zero.

cpython/Modules/_lzmamodule.c

Lines 1487 to 1495 in 01cc9c1

lzret = lzma_properties_decode(
&filter, NULL, encoded_props->buf, encoded_props->len);
if (catch_lzma_error(state, lzret)) {
return NULL;
}
result = build_filter_spec(&filter);

Then, in build_filter_spec, access to f->options->start_offset leads to segmentation fault:

}
case LZMA_FILTER_X86:
case LZMA_FILTER_POWERPC:
case LZMA_FILTER_IA64:
case LZMA_FILTER_ARM:
case LZMA_FILTER_ARMTHUMB:
case LZMA_FILTER_SPARC: {
lzma_options_bcj *options = f->options;
ADD_FIELD(options, start_offset);
break;
}

The PR is on the way.
3.9-3.12 are affected for sure.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibPython modules in the Lib dirtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions