diff mbox series

[meta-multimedia,wrynose,14/22] libheif: patch CVE-2026-62377

Message ID 20260903094954.3240723-14-ankur.tyagi85@gmail.com
State New
Headers show
Series [meta-oe,wrynose,1/22] jq: ignore CVE-2025-49014 | expand

Commit Message

Ankur Tyagi Sept. 3, 2026, 9:49 a.m. UTC
From: Ankur Tyagi <ankur.tyagi85@gmail.com>

Details:
https://nvd.nist.gov/vuln/detail/CVE-2026-62377

Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
---
 .../libheif/libheif/CVE-2026-62377.patch      | 175 ++++++++++++++++++
 .../libheif/libheif_1.21.2.bb                 |   1 +
 2 files changed, 176 insertions(+)
 create mode 100644 meta-multimedia/recipes-multimedia/libheif/libheif/CVE-2026-62377.patch
diff mbox series

Patch

diff --git a/meta-multimedia/recipes-multimedia/libheif/libheif/CVE-2026-62377.patch b/meta-multimedia/recipes-multimedia/libheif/libheif/CVE-2026-62377.patch
new file mode 100644
index 0000000000..5481c198b6
--- /dev/null
+++ b/meta-multimedia/recipes-multimedia/libheif/libheif/CVE-2026-62377.patch
@@ -0,0 +1,175 @@ 
+From cace54a7491cd8eb46617f17ca7078182d9903b0 Mon Sep 17 00:00:00 2001
+From: Dirk Farin <dirk.farin@gmail.com>
+Date: Fri, 26 Jun 2026 10:03:31 +0200
+Subject: [PATCH] Return error instead of asserting in get_track() without
+ sequence (#1844)
+
+HeifContext::get_track() asserted has_sequence() up front. Calling the
+public heif_context_get_track() on a context that has no sequence tracks
+(e.g. a still image, or a crafted sequence file accepted with zero tracks)
+therefore aborted the process via the assert, instead of letting the public
+wrapper return the documented nullptr. In NDEBUG builds the assert was
+compiled out and the track_id==0 path dereferenced begin() on an empty map.
+
+Replace the assert with a normal error return so the public wrapper hands
+the caller nullptr as documented.
+
+(cherry picked from commit e1a0bc1c1ae74f8075eaca30a1cdb2b9bee698d3)
+
+CVE: CVE-2026-62377
+Upstream-Status: Backport [https://github.com/strukturag/libheif/commit/e1a0bc1c1ae74f8075eaca30a1cdb2b9bee698d3]
+
+Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
+---
+ libheif/context.cc         |   9 +++-
+ tests/CMakeLists.txt       |   1 +
+ tests/sequence_no_track.cc | 108 +++++++++++++++++++++++++++++++++++++
+ 3 files changed, 117 insertions(+), 1 deletion(-)
+ create mode 100644 tests/sequence_no_track.cc
+
+diff --git a/libheif/context.cc b/libheif/context.cc
+index a3371207..170f8314 100644
+--- a/libheif/context.cc
++++ b/libheif/context.cc
+@@ -1945,7 +1945,14 @@ std::vector<uint32_t> HeifContext::get_track_IDs() const
+ 
+ Result<std::shared_ptr<Track>> HeifContext::get_track(uint32_t track_id)
+ {
+-  assert(has_sequence());
++  // The caller is expected to have confirmed (via has_sequence()) that there are
++  // sequence tracks before requesting one. Guard against an empty track map anyway,
++  // since this is reachable through the public API (e.g. on a still image file).
++  if (!has_sequence()) {
++    return Error{heif_error_Usage_error,
++                 heif_suberror_Unspecified,
++                 "File contains no sequence tracks"};
++  }
+ 
+   if (track_id != 0) {
+     auto iter = m_tracks.find(track_id);
+diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
+index b52bc202..d66ffb38 100644
+--- a/tests/CMakeLists.txt
++++ b/tests/CMakeLists.txt
+@@ -59,6 +59,7 @@ endif()
+ add_libheif_test(encode)
+ add_libheif_test(extended_type)
+ add_libheif_test(region)
++add_libheif_test(sequence_no_track)
+ add_libheif_test(tai)
+ add_libheif_test(text)
+ add_libheif_test(cxx_wrapper)
+diff --git a/tests/sequence_no_track.cc b/tests/sequence_no_track.cc
+new file mode 100644
+index 00000000..cde11f77
+--- /dev/null
++++ b/tests/sequence_no_track.cc
+@@ -0,0 +1,108 @@
++/*
++  libheif regression test for requesting a track from a context without sequence tracks.
++
++  MIT License
++
++  Copyright (c) 2026 Dirk Farin <dirk.farin@gmail.com>
++
++  Permission is hereby granted, free of charge, to any person obtaining a copy
++  of this software and associated documentation files (the "Software"), to deal
++  in the Software without restriction, including without limitation the rights
++  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++  copies of the Software, and to permit persons to whom the Software is
++  furnished to do so, subject to the following conditions:
++
++  The above copyright notice and this permission notice shall be included in all
++  copies or substantial portions of the Software.
++
++  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
++  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
++  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
++  SOFTWARE.
++*/
++
++#include "catch_amalgamated.hpp"
++#include "libheif/heif.h"
++#include "libheif/heif_sequences.h"
++#include "test_utils.h"
++
++#include <cstdint>
++#include <vector>
++
++namespace {
++
++// Sequence API queries that must work on a context that holds no sequence
++// tracks (a still image, or no image at all). heif_context_get_track() is
++// documented to return nullptr on failure; it must not abort/crash. This
++// formerly tripped assert(has_sequence()) in HeifContext::get_track().
++// See https://github.com/strukturag/libheif/issues/1844.
++void check_no_sequence_apis(heif_context* ctx)
++{
++  REQUIRE(heif_context_has_sequence(ctx) == 0);
++  REQUIRE(heif_context_number_of_sequence_tracks(ctx) == 0);
++
++  // Listing track IDs must work (and write nothing) when there are no tracks.
++  heif_context_get_track_ids(ctx, nullptr);
++
++  heif_track* track = heif_context_get_track(ctx, 0);
++  REQUIRE(track == nullptr);
++}
++
++heif_error mem_writer(heif_context*, const void* data, size_t size, void* userdata)
++{
++  auto* out = static_cast<std::vector<uint8_t>*>(userdata);
++  const auto* p = static_cast<const uint8_t*>(data);
++  out->insert(out->end(), p, p + size);
++  return heif_error{heif_error_Ok, heif_suberror_Unspecified, nullptr};
++}
++
++}
++
++TEST_CASE("get_track on context without sequence returns nullptr")
++{
++  heif_context* ctx = heif_context_alloc();
++  REQUIRE(ctx != nullptr);
++
++  // Fresh context, nothing loaded: no sequence tracks present.
++  check_no_sequence_apis(ctx);
++
++  heif_context_free(ctx);
++}
++
++TEST_CASE("get_track on a still-image file returns nullptr")
++{
++  // Encode a tiny still image to an in-memory HEIF file, then read it back.
++  // A still image is a perfectly valid file that contains no sequence tracks.
++  heif_image* img = nullptr;
++  REQUIRE(heif_image_create(16, 16, heif_colorspace_YCbCr, heif_chroma_420, &img).code == heif_error_Ok);
++  fill_new_plane(img, heif_channel_Y, 16, 16);
++  fill_new_plane(img, heif_channel_Cb, 8, 8);
++  fill_new_plane(img, heif_channel_Cr, 8, 8);
++
++  heif_encoder* enc = get_encoder_or_skip_test(heif_compression_HEVC);
++
++  heif_context* enc_ctx = heif_context_alloc();
++  REQUIRE(heif_context_encode_image(enc_ctx, img, enc, nullptr, nullptr).code == heif_error_Ok);
++
++  std::vector<uint8_t> file;
++  heif_writer writer{};
++  writer.writer_api_version = 1;
++  writer.write = mem_writer;
++  REQUIRE(heif_context_write(enc_ctx, &writer, &file).code == heif_error_Ok);
++
++  heif_encoder_release(enc);
++  heif_context_free(enc_ctx);
++  heif_image_release(img);
++
++  // Read the still image back and query the sequence API on it.
++  heif_context* ctx = heif_context_alloc();
++  REQUIRE(ctx != nullptr);
++  REQUIRE(heif_context_read_from_memory(ctx, file.data(), file.size(), nullptr).code == heif_error_Ok);
++
++  check_no_sequence_apis(ctx);
++
++  heif_context_free(ctx);
++}
diff --git a/meta-multimedia/recipes-multimedia/libheif/libheif_1.21.2.bb b/meta-multimedia/recipes-multimedia/libheif/libheif_1.21.2.bb
index 1dfab46513..165ed0ad2a 100644
--- a/meta-multimedia/recipes-multimedia/libheif/libheif_1.21.2.bb
+++ b/meta-multimedia/recipes-multimedia/libheif/libheif_1.21.2.bb
@@ -15,6 +15,7 @@  SRC_URI = "git://github.com/strukturag/libheif.git;protocol=https;branch=master;
            file://CVE-2026-41071-1.patch \
            file://CVE-2026-41071-2.patch \
            file://CVE-2026-62289.patch \
+           file://CVE-2026-62377.patch \
            "
 
 SRCREV = "62f1b8c76ed4d8305071fdacbe74ef9717bacac5"