Commit 35be0c1a for libheif

commit 35be0c1a6aceed744cc2ea61fce68999bfaa8178
Author: Simone Caronni <negativo17@gmail.com>
Date:   Tue Sep 15 15:33:11 2026 +0200

    Fix HEVC test

    The x265 plugin calls api->encoder_headers() as soon as a sequence encoder is opened, and encode_sequence_frame() calls get_data() immediately afterwards; before any frame is encoded.

    That call sees three parameter-set NALs and nothing else, so the optional is still empty when line 260 dereferences it. That is turned into the _M_is_engaged() abort instead of silent UB because of Fedora's default GCC option -Wp,-D_GLIBCXX_ASSERTIONS.

diff --git a/libheif/codecs/hevc_enc.cc b/libheif/codecs/hevc_enc.cc
index e6cc45fc..20186582 100644
--- a/libheif/codecs/hevc_enc.cc
+++ b/libheif/codecs/hevc_enc.cc
@@ -247,6 +247,17 @@ Error Encoder_HEVC::get_data(heif_encoder* encoder)
     return {};
   }

+  // The encoder can hand out parameter-set NALs before any slice data. x265,
+  // for example, emits VPS/SPS/PPS from encoder_headers() as soon as the
+  // sequence encoder is opened, so the first get_data() after
+  // start_sequence_encoding() sees only headers. Those are collected into
+  // m_hvcC and leave m_current_output_data unset, so there is no coded
+  // image to report yet. Without this check the dereferences below run on a
+  // disengaged std::optional.
+  if (!m_current_output_data) {
+    return {};
+  }
+
   if (!m_encoded_image_width || !m_encoded_image_height) {
     return Error(heif_error_Encoder_plugin_error,
                  heif_suberror_Invalid_image_size);
diff --git a/libheif/codecs/vvc_enc.cc b/libheif/codecs/vvc_enc.cc
index bb8d83a0..df4ae0f3 100644
--- a/libheif/codecs/vvc_enc.cc
+++ b/libheif/codecs/vvc_enc.cc
@@ -253,6 +253,17 @@ Error Encoder_VVC::get_data(heif_encoder* encoder)
     return {};
   }

+  // The encoder can hand out parameter-set NALs before any slice data. x265,
+  // for example, emits VPS/SPS/PPS from encoder_headers() as soon as the
+  // sequence encoder is opened, so the first get_data() after
+  // start_sequence_encoding() sees only headers. Those are collected into
+  // m_vvcC and leave m_current_output_data unset, so there is no coded
+  // image to report yet. Without this check the dereferences below run on a
+  // disengaged std::optional.
+  if (!m_current_output_data) {
+    return {};
+  }
+
   if (!m_encoded_image_width || !m_encoded_image_height) {
     return Error(heif_error_Encoder_plugin_error,
                  heif_suberror_Invalid_image_size);