Skip to content

Commit

Permalink
Apply nits
Browse files Browse the repository at this point in the history
  • Loading branch information
y-guyon committed Nov 15, 2024
1 parent 77998bc commit 65806a5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/avif/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ typedef enum avifSampleTransformRecipe
// ---------------------------------------------------------------------------
// Opaque image item properties

// This struct represents an opaque ItemProperty (Box) or ItemFullProperty (FullBox) in ISO/IEC 14496-12.
typedef struct avifImageItemProperty
{
uint8_t boxtype[4]; // boxtype as defined in ISO/IEC 14496-12.
Expand Down
2 changes: 1 addition & 1 deletion include/avif/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ AVIF_API avifResult avifImagePushProperty(avifImage * image,
const uint8_t boxtype[4],
const uint8_t usertype[16],
const uint8_t * boxPayload,
size_t boxPayloadLength);
size_t boxPayloadSize);

// ---------------------------------------------------------------------------

Expand Down
9 changes: 5 additions & 4 deletions src/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static avifResult avifImageCopyProperties(avifImage * dstImage, const avifImage
dstImage->numProperties = 0;

if (srcImage->numProperties != 0) {
dstImage->properties = avifAlloc(srcImage->numProperties * sizeof(srcImage->properties[0]));
dstImage->properties = (avifImageItemProperty *)avifAlloc(srcImage->numProperties * sizeof(srcImage->properties[0]));
AVIF_CHECKERR(dstImage->properties != NULL, AVIF_RESULT_OUT_OF_MEMORY);
memset(dstImage->properties, 0, srcImage->numProperties * sizeof(srcImage->properties[0]));
dstImage->numProperties = srcImage->numProperties;
Expand Down Expand Up @@ -375,6 +375,7 @@ void avifImageDestroy(avifImage * image)
}
avifFree(image->properties);
image->properties = NULL;
image->numProperties = 0;
avifFree(image);
}

Expand All @@ -388,12 +389,12 @@ avifResult avifImageSetMetadataXMP(avifImage * image, const uint8_t * xmp, size_
return avifRWDataSet(&image->xmp, xmp, xmpSize);
}

avifResult avifImagePushProperty(avifImage * image, const uint8_t boxtype[4], const uint8_t usertype[16], const uint8_t * boxPayload, size_t boxPayloadLength)
avifResult avifImagePushProperty(avifImage * image, const uint8_t boxtype[4], const uint8_t usertype[16], const uint8_t * boxPayload, size_t boxPayloadSize)
{
AVIF_CHECKERR(image->numProperties < SIZE_MAX / sizeof(avifImageItemProperty), AVIF_RESULT_INVALID_ARGUMENT);
// Shallow copy the current properties.
const size_t numProperties = image->numProperties + 1;
avifImageItemProperty * const properties = avifAlloc(numProperties * sizeof(properties[0]));
avifImageItemProperty * const properties = (avifImageItemProperty *)avifAlloc(numProperties * sizeof(properties[0]));
AVIF_CHECKERR(properties != NULL, AVIF_RESULT_OUT_OF_MEMORY);
if (image->numProperties != 0) {
memcpy(properties, image->properties, image->numProperties * sizeof(properties[0]));
Expand All @@ -407,7 +408,7 @@ avifResult avifImagePushProperty(avifImage * image, const uint8_t boxtype[4], co
memset(property, 0, sizeof(*property));
memcpy(property->boxtype, boxtype, sizeof(property->boxtype));
memcpy(property->usertype, usertype, sizeof(property->usertype));
AVIF_CHECKRES(avifRWDataSet(&property->boxPayload, boxPayload, boxPayloadLength));
AVIF_CHECKRES(avifRWDataSet(&property->boxPayload, boxPayload, boxPayloadSize));
return AVIF_RESULT_OK;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/gtest/avif_fuzztest_dec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void Decode(const std::string& arbitrary_bytes, bool is_persistent,
if (avifDecoderParse(decoder.get()) != AVIF_RESULT_OK) return;

for (size_t i = 0; i < decoder->image->numProperties; ++i) {
const avifRWData& boxPayload = decoder->image->properties[i].boxPayload;
const avifRWData& box_payload = decoder->image->properties[i].boxPayload;
// Each custom property should be found as is in the input bitstream.
EXPECT_NE(std::search(data, data + arbitrary_bytes.size(), boxPayload.data,
boxPayload.data + boxPayload.size),
EXPECT_NE(std::search(data, data + arbitrary_bytes.size(), box_payload.data,
box_payload.data + box_payload.size),
data + arbitrary_bytes.size());
}

Expand Down

0 comments on commit 65806a5

Please sign in to comment.