Repository navigation
Conversation
…/alpha images When encoding monochrome (P400) or alpha images with Kvazaar, kvazaar_start_sequence_encoding_intern() only set config->input_format = KVZ_FORMAT_P400 without updating config->chroma_format or calling api->config_parse(). Because kvz_config_init() defaults chroma_format to KVZ_CSP_420, Kvazaar's encoder internal state retained 4:2:0. Meanwhile, kvazaar_encode_sequence_frame() allocated the picture buffer with KVZ_CSP_400, leaving pic->u and pic->v as NULL. During encoding, Kvazaar's intra search checked state->encoder_control->cfg.chroma_format != KVZ_CSP_400 and dereferenced the NULL chroma planes, causing a SIGSEGV / access violation (0xC0000005). Fix this by setting config->chroma_format and calling api->config_parse(config, "input-format", format_str) for all supported chroma formats. Also add a regression unit test.
farindk
added a commit
that referenced
this pull request
Sep 21, 2026
kvazaar git master (cbdcc31a, 2026-07-27) keeps the encoder chroma format in new kvz_config fields that default to 4:2:0 and are only updated by the "input-format" parser. Writing config->input_format directly leaves them at 4:2:0, so every monochrome encode, including every alpha auxiliary image, dereferences the NULL chroma planes of the 4:0:0 input picture. Released kvazaar versions derive the chroma format from input_format and are not affected. Set the input format through api->config_parse(), which is how kvazaar's own CLI configures the encoder and works on every version. Chroma formats a kvazaar build does not support are rejected by the parser and now return an error instead of running the encoder in a mode it was not built for. Reported by @twn39 in #1915, whose regression test this includes.
Member
|
Thanks for the report and the analysis. The crash is real, but only against kvazaar git master since July 2026 (commit cbdcc31a moved chroma_format into kvz_config). The fields your patch writes do not exist in any released kvazaar, so the PR does not compile against 2.3.x. The portable fix is to configure the input format through config_parse("input-format", ...), which is what kvazaar's own CLI does and which works on every version. I've applied that variant together with your test in d3772c0. |
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.
Summary
Fixes a crash (NULL pointer dereference / SIGSEGV / Windows Access Violation
0xC0000005) when encoding monochrome images (heif_colorspace_monochrome) or images with an Alpha channel using the Kvazaar HEVC encoder.Root Cause
In
kvazaar_start_sequence_encoding_intern()(libheif/plugins/encoder_kvazaar.cc):config->input_format = KVZ_FORMAT_P400;kvz_config_init()initializesconfig->chroma_formattoKVZ_CSP_420by default.config->chroma_formatto be updated (orkvz_config_parse(config, "input-format", "P400")to be invoked), which setschroma_format = KVZ_CSP_400andchroma_shift_w = 0, chroma_shift_h = 0.chroma_formatwas never changed fromKVZ_CSP_420, Kvazaar's encoder was created expecting 4:2:0 input.kvazaar_encode_sequence_frame(), the picture was allocated viaapi->picture_alloc_csp(KVZ_CSP_400, ...). In Kvazaar'svideoframe.c,KVZ_CSP_400does not allocate U and V chroma planes, settingpic->u = NULL; pic->v = NULL;.api->encoder_encode()ran, Kvazaar's intra mode search (search_intra.c: search_intra_chroma_rough) checkedstate->encoder_control->cfg.chroma_format != KVZ_CSP_400. Becausecfg.chroma_formatwas stillKVZ_CSP_420, it attempted to accesspic->uandpic->v, resulting in an immediate crash dereferencing NULL.Solution
kvazaar_start_sequence_encoding_intern(), explicitly setconfig->chroma_formatand corresponding chroma shift parameters.api->config_parse(config, "input-format", format_str)to ensure Kvazaar's internal configuration state is fully synchronized.kvazaar encodes monochrome imageintests/encode.cc.