Skip to content

Instantly share code, notes, and snippets.

@hjanuschka
Last active March 31, 2026 22:05
Show Gist options
  • Select an option

  • Save hjanuschka/842c07396af340980ebc7387b6b3c950 to your computer and use it in GitHub Desktop.

Select an option

Save hjanuschka/842c07396af340980ebc7387b6b3c950 to your computer and use it in GitHub Desktop.
Chromium JXL regression test: incremental CMYK ICC metadata visibility (crbug.com/498155364)
// Source: chromium/src/third_party/blink/renderer/platform/image-decoders/jxl/jxl_image_decoder_test.cc
// Regression test for crbug.com/498155364.
// With incremental input, basic image info should not become observable before
// the embedded ICC profile is parsed.
TEST_F(JXLImageDecoderTest, DecodeCmykIccProfileIncrementalNoCrash) {
scoped_refptr<SharedBuffer> full_data =
ReadFileToSharedBuffer(kJxlTestDir, "conformance_cmyk_layers.jxl");
ASSERT_TRUE(full_data);
Vector<char> full_data_vec = full_data->CopyAs<Vector<char>>();
ASSERT_GT(full_data_vec.size(), 0u);
auto decoder = CreateJXLDecoder();
constexpr wtf_size_t kChunkSize = 256;
for (wtf_size_t chunk_end = kChunkSize;
chunk_end < static_cast<wtf_size_t>(full_data_vec.size());
chunk_end += kChunkSize) {
scoped_refptr<SharedBuffer> partial_data =
SharedBuffer::Create(base::span(full_data_vec).first(chunk_end));
// Before the patch, this SetData() call could expose size/basic-info while
// ICC metadata was still missing. Blink would then configure pixel format
// early, which led to a Rust panic in the CMYK path.
decoder->SetData(partial_data.get(), false);
EXPECT_FALSE(decoder->Failed())
<< "Decoder failed during incremental CMYK+ICC metadata scan at "
<< chunk_end << " bytes";
if (decoder->IsSizeAvailable()) {
// This assertion captures the pre-patch bad state. Historically this
// branch could be reached with HasEmbeddedColorProfile()==false, and the
// next decode steps could crash.
EXPECT_TRUE(decoder->HasEmbeddedColorProfile())
<< "Size became available before embedded ICC profile parsing "
"completed";
}
}
decoder->SetData(full_data.get(), true);
EXPECT_TRUE(decoder->IsSizeAvailable());
EXPECT_TRUE(decoder->HasEmbeddedColorProfile());
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(0);
ASSERT_TRUE(frame);
EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
EXPECT_TRUE(frame->HasAlpha());
EXPECT_FALSE(decoder->Failed());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment