Skip XMP items in avifEncoderDecodeSatoBaseImage() (#2943)

diff --git a/src/write.c b/src/write.c
index 654e991..c00ded3 100644
--- a/src/write.c
+++ b/src/write.c
@@ -1404,6 +1404,9 @@
     // Find the encoded bytes of the base image item.
     for (uint32_t itemIndex = 0; itemIndex < encoder->data->items.count; ++itemIndex) {
         avifEncoderItem * item = &encoder->data->items.item[itemIndex];
+        if (item->codec == NULL) {
+            continue; // Non-image item such as metadata.
+        }
         if ((item->itemCategory != AVIF_ITEM_COLOR || planes != AVIF_PLANES_YUV) &&
             (item->itemCategory != AVIF_ITEM_ALPHA || planes != AVIF_PLANES_A)) {
             continue;
diff --git a/tests/gtest/avif16bittest.cc b/tests/gtest/avif16bittest.cc
index 337c47f..c38a379 100644
--- a/tests/gtest/avif16bittest.cc
+++ b/tests/gtest/avif16bittest.cc
@@ -18,9 +18,9 @@
 const char* data_path = nullptr;
 
 class SampleTransformTest
-    : public testing::TestWithParam<
-          std::tuple<avifSampleTransformRecipe, avifPixelFormat,
-                     /*create_alpha=*/bool, /*quality=*/int>> {};
+    : public testing::TestWithParam<std::tuple<
+          avifSampleTransformRecipe, avifPixelFormat, /*create_alpha=*/bool,
+          /*quality=*/int, /*add_xmp=*/bool>> {};
 
 //------------------------------------------------------------------------------
 
@@ -29,6 +29,7 @@
   const avifPixelFormat yuv_format = std::get<1>(GetParam());
   const bool create_alpha = std::get<2>(GetParam());
   const int quality = std::get<3>(GetParam());
+  const bool add_xmp = std::get<4>(GetParam());
 
   const ImagePtr image = testutil::ReadImage(
       data_path, "weld_16bit.png", yuv_format, /*requested_depth=*/16);
@@ -39,6 +40,11 @@
     image->alphaRowBytes = image->yuvRowBytes[AVIF_CHAN_Y];
     image->imageOwnsAlphaPlane = false;
   }
+  if (add_xmp) {
+    const uint8_t xmp[] = {1, 2, 3, 4};
+    ASSERT_EQ(avifImageSetMetadataXMP(image.get(), xmp, sizeof(xmp)),
+              AVIF_RESULT_OK);
+  }
 
   EncoderPtr encoder(avifEncoderCreate());
   ASSERT_NE(encoder, nullptr);
@@ -106,8 +112,8 @@
         testing::Values(AVIF_PIXEL_FORMAT_YUV444, AVIF_PIXEL_FORMAT_YUV420,
                         AVIF_PIXEL_FORMAT_YUV400),
         /*create_alpha=*/testing::Values(false),
-        /*quality=*/
-        testing::Values(AVIF_QUALITY_DEFAULT)));
+        testing::Values(AVIF_QUALITY_DEFAULT),
+        /*add_xmp=*/testing::Values(false)));
 
 INSTANTIATE_TEST_SUITE_P(
     BitDepthExtensions, SampleTransformTest,
@@ -116,8 +122,8 @@
                         AVIF_SAMPLE_TRANSFORM_BIT_DEPTH_EXTENSION_12B_4B),
         testing::Values(AVIF_PIXEL_FORMAT_YUV444),
         /*create_alpha=*/testing::Values(false),
-        /*quality=*/
-        testing::Values(AVIF_QUALITY_LOSSLESS)));
+        testing::Values(AVIF_QUALITY_LOSSLESS),
+        /*add_xmp=*/testing::Values(false)));
 
 INSTANTIATE_TEST_SUITE_P(
     ResidualBitDepthExtension, SampleTransformTest,
@@ -126,8 +132,8 @@
             AVIF_SAMPLE_TRANSFORM_BIT_DEPTH_EXTENSION_12B_8B_OVERLAP_4B),
         testing::Values(AVIF_PIXEL_FORMAT_YUV444),
         /*create_alpha=*/testing::Values(false),
-        /*quality=*/
-        testing::Values(AVIF_QUALITY_DEFAULT)));
+        testing::Values(AVIF_QUALITY_DEFAULT),
+        /*add_xmp=*/testing::Values(false)));
 
 INSTANTIATE_TEST_SUITE_P(
     Alpha, SampleTransformTest,
@@ -135,8 +141,18 @@
         testing::Values(AVIF_SAMPLE_TRANSFORM_BIT_DEPTH_EXTENSION_8B_8B),
         testing::Values(AVIF_PIXEL_FORMAT_YUV444),
         /*create_alpha=*/testing::Values(true),
-        /*quality=*/
-        testing::Values(AVIF_QUALITY_LOSSLESS)));
+        testing::Values(AVIF_QUALITY_LOSSLESS),
+        /*add_xmp=*/testing::Values(false)));
+
+INSTANTIATE_TEST_SUITE_P(
+    WithXmp, SampleTransformTest,
+    testing::Combine(
+        testing::Values(
+            AVIF_SAMPLE_TRANSFORM_BIT_DEPTH_EXTENSION_12B_8B_OVERLAP_4B),
+        testing::Values(AVIF_PIXEL_FORMAT_YUV444),
+        /*create_alpha=*/testing::Values(false),
+        testing::Values(AVIF_QUALITY_LOSSLESS),
+        /*add_xmp=*/testing::Values(true)));
 
 // TODO(yguyon): Test grids with bit depth extensions.