Commit bfb51847fa for aom

commit bfb51847fa03803b0b66467285966de0a143529e
Author: Wan-Teh Chang <wtc@google.com>
Date:   Mon Aug 31 13:54:08 2026 -0700

    Check frame size is max when frame_size_override=0

    In write_frame_size(), if frame_size_override is 0, frame_width_minus_1
    and frame_height_minus_1 are omitted because they are inferred to be
    equal to the maximum frame width and height in the sequence header.
    Report an error if that is not the case.

    Remove a related assertion for reduced_still_picture_hdr=1 in
    write_uncompressed_header_obu() because it is replaced by the error
    checking in write_frame_size().

    Bug: 555350218
    Change-Id: I24258517258a06f40df6f409ada19ed6d5d3629b

diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 53ca4adac1..3fc0165f08 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -2367,13 +2367,20 @@ static inline void write_frame_size(const AV1_COMMON *cm,
                                     struct aom_write_bit_buffer *wb) {
   const int coded_width = cm->superres_upscaled_width - 1;
   const int coded_height = cm->superres_upscaled_height - 1;
+  const SequenceHeader *seq_params = cm->seq_params;

   if (frame_size_override) {
-    const SequenceHeader *seq_params = cm->seq_params;
     int num_bits_width = seq_params->num_bits_width;
     int num_bits_height = seq_params->num_bits_height;
     aom_wb_write_literal(wb, coded_width, num_bits_width);
     aom_wb_write_literal(wb, coded_height, num_bits_height);
+  } else {
+    if (cm->superres_upscaled_width != seq_params->max_frame_width ||
+        cm->superres_upscaled_height != seq_params->max_frame_height) {
+      aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM,
+                         "Frame dimensions are different from the maximum "
+                         "values when frame_size_override_flag is 0");
+    }
   }

   write_superres_scale(cm, wb);
@@ -2977,10 +2984,7 @@ static inline void write_uncompressed_header_obu(

   int frame_size_override_flag = 0;

-  if (seq_params->reduced_still_picture_hdr) {
-    assert(cm->superres_upscaled_width == seq_params->max_frame_width &&
-           cm->superres_upscaled_height == seq_params->max_frame_height);
-  } else {
+  if (!seq_params->reduced_still_picture_hdr) {
     if (seq_params->frame_id_numbers_present_flag) {
       int frame_id_len = seq_params->frame_id_length;
       aom_wb_write_literal(wb, cm->current_frame_id, frame_id_len);
diff --git a/test/forced_max_frame_width_height_test.cc b/test/forced_max_frame_width_height_test.cc
index 5211d665b9..d5bbdf25ae 100644
--- a/test/forced_max_frame_width_height_test.cc
+++ b/test/forced_max_frame_width_height_test.cc
@@ -277,4 +277,37 @@ TEST(EncodeForcedMaxFrameWidthHeight, SecondFrameTooBig) {
   EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
 }

+// A regression test for bug 555350218.
+TEST(EncodeForcedMaxFrameWidthHeight, ReducedStillPictureHeader) {
+  constexpr size_t kImageDataSize = 128 * 128 + 2 * 64 * 64;
+  std::unique_ptr<unsigned char[]> img_data(new unsigned char[kImageDataSize]);
+  ASSERT_NE(img_data, nullptr);
+  memset(img_data.get(), 128, kImageDataSize);
+  aom_image_t img;
+  EXPECT_EQ(&img,
+            aom_img_wrap(&img, AOM_IMG_FMT_I420, 128, 128, 1, img_data.get()));
+
+  aom_codec_iface_t *iface = aom_codec_av1_cx();
+  aom_codec_enc_cfg_t cfg;
+  EXPECT_EQ(AOM_CODEC_OK,
+            aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_REALTIME));
+  cfg.g_w = 128;
+  cfg.g_h = 128;
+  cfg.g_limit = 1;
+
+  aom_codec_ctx_t enc;
+
+  cfg.g_forced_max_frame_width = 128;
+  cfg.g_forced_max_frame_height = 128;
+  EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0));
+  EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
+  EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
+
+  cfg.g_forced_max_frame_width = 256;
+  cfg.g_forced_max_frame_height = 256;
+  EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0));
+  EXPECT_NE(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
+  EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
+}
+
 }  // namespace