Skip to content

Commit

Permalink
Annotate ICC
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Jan 17, 2025
1 parent 708abbd commit 13428a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/ci-unix-static-sanitized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,41 @@ jobs:
run: |
sed -i -e 's/cmake -S \(.*\)/cmake -S \1 -DWITH_SIMD=OFF/g' libjpeg.cmd
./libjpeg.cmd
env:
CFLAGS: ${{ env.CI_CFLAGS }}
CXXFLAGS: ${{ env.CI_CXXFLAGS }}
LDFLAGS: ${{ env.CI_LDFLAGS }}
LD_LIBRARY_PATH: ${{ env.CI_LD_LIBRARY_PATH }}

- name: Build aom for msan
- name: Prepare aom for msan
if: ${{ (steps.cache-hit.outputs.hit == 'false') && (matrix.sanitizer == 'memory')}}
working-directory: ./ext
run: |
run:
sed -i -e 's/cmake -G Ninja \(.*\) \.\./cmake -G Ninja \1 -DAOM_TARGET_CPU=generic -DSANITIZE=${{ matrix.sanitizer }} ../g' aom.cmd
./aom.cmd
- name: Build aom for other sanitizers
- name: Prepare aom for other sanitizers
if: ${{ (steps.cache-hit.outputs.hit == 'false') && (matrix.sanitizer != 'memory')}}
working-directory: ./ext
run: |
run:
sed -i -e 's/cmake -G Ninja \(.*\) \.\./cmake -G Ninja \1 -DSANITIZE=${{ matrix.sanitizer }} ../g' aom.cmd
- name: Build aom
working-directory: ./ext
run:
./aom.cmd
env:
CFLAGS: ${{ env.CI_CFLAGS }}
CXXFLAGS: ${{ env.CI_CXXFLAGS }}
LDFLAGS: ${{ env.CI_LDFLAGS }}
LD_LIBRARY_PATH: ${{ env.CI_LD_LIBRARY_PATH }}

- name: Prepare dav1d for msan
if: ${{ (steps.cache-hit.outputs.hit == 'false') && (matrix.sanitizer == 'memory') }}
working-directory: ./ext
run: |
run:
sed -i -e 's/meson setup \(.*\) \.\./meson setup \1 -Db_sanitize=memory -Db_lundef=false -Denable_asm=false ../g' dav1d.cmd
- name: Prepare dav1d for other sanitizers
if: ${{ (steps.cache-hit.outputs.hit == 'false') && (matrix.sanitizer != 'memory') }}
working-directory: ./ext
run: |
run:
sed -i -e 's/meson setup \(.*\) \.\./meson setup \1 -Db_sanitize=${{ matrix.sanitizer }} -Db_lundef=false ../g' dav1d.cmd
- name: Build dav1d
if: ${{ steps.cache-hit.outputs.hit == 'false' }}
Expand Down
24 changes: 2 additions & 22 deletions apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
#include <libxml/parser.h>
#endif

#if defined(__clang__) && defined(__has_feature)
#if __has_feature(memory_sanitizer)
#include <sanitizer/msan_interface.h>
#define AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) __msan_unpoison(address, size)
#endif
#endif
#if !defined(AVIF_ANNOTATE_MEMORY_IS_INITIALIZED)
#define AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
do { \
} while (0)
#endif

#define AVIF_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define AVIF_MAX(a, b) (((a) > (b)) ? (a) : (b))

Expand Down Expand Up @@ -989,11 +977,8 @@ static avifBool avifJPEGReadInternal(FILE * f,

int row = 0;
while (cinfo.output_scanline < cinfo.output_height) {
if (jpeg_read_scanlines(&cinfo, buffer, 1) < 1) {
goto cleanup;
}
jpeg_read_scanlines(&cinfo, buffer, 1);
uint8_t * pixelRow = &rgb.pixels[row * rgb.rowBytes];
AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(buffer[0], rgb.rowBytes);
memcpy(pixelRow, buffer[0], rgb.rowBytes);
++row;
}
Expand Down Expand Up @@ -1359,12 +1344,10 @@ avifBool avifJPEGWrite(const char * outputFilename, const avifImage * avif, int

avifROData remainingExif = { exif.data, exif.size };
while (remainingExif.size > AVIF_JPEG_MAX_MARKER_DATA_LENGTH) {
AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(remainingExif.data, AVIF_JPEG_MAX_MARKER_DATA_LENGTH);
jpeg_write_marker(&cinfo, JPEG_APP0 + 1, remainingExif.data, AVIF_JPEG_MAX_MARKER_DATA_LENGTH);
remainingExif.data += AVIF_JPEG_MAX_MARKER_DATA_LENGTH;
remainingExif.size -= AVIF_JPEG_MAX_MARKER_DATA_LENGTH;
}
AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(remainingExif.data, remainingExif.size);
jpeg_write_marker(&cinfo, JPEG_APP0 + 1, remainingExif.data, (unsigned int)remainingExif.size);
avifRWDataFree(&exif);
} else if (avifImageGetExifOrientationFromIrotImir(avif) != 1) {
Expand Down Expand Up @@ -1396,17 +1379,14 @@ avifBool avifJPEGWrite(const char * outputFilename, const avifImage * avif, int
}
memcpy(xmp.data, AVIF_JPEG_STANDARD_XMP_TAG, AVIF_JPEG_STANDARD_XMP_TAG_LENGTH);
memcpy(xmp.data + AVIF_JPEG_STANDARD_XMP_TAG_LENGTH, avif->xmp.data, avif->xmp.size);
AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(xmp.data, xmp.size);
jpeg_write_marker(&cinfo, JPEG_APP0 + 1, xmp.data, (unsigned int)xmp.size);
avifRWDataFree(&xmp);
}
}

while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = &rgb.pixels[cinfo.next_scanline * rgb.rowBytes];
if (jpeg_write_scanlines(&cinfo, row_pointer, 1) < 1) {
goto cleanup;
}
(void)jpeg_write_scanlines(&cinfo, row_pointer, 1);
}

jpeg_finish_compress(&cinfo);
Expand Down
14 changes: 14 additions & 0 deletions third_party/iccjpeg/iccjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
#include "iccjpeg.h"
#include <stdlib.h> /* define malloc() */

#if defined(__clang__) && defined(__has_feature)
#if __has_feature(memory_sanitizer)
#include <sanitizer/msan_interface.h>
#define AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) __msan_unpoison(address, size)
#endif
#endif
#if !defined(AVIF_ANNOTATE_MEMORY_IS_INITIALIZED)
#define AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
do { \
} while (0)
#endif

/*
* Since an ICC profile can be larger than the maximum size of a JPEG marker
Expand Down Expand Up @@ -123,6 +134,9 @@ setup_read_icc_profile (j_decompress_ptr cinfo)
static boolean
marker_is_icc (jpeg_saved_marker_ptr marker)
{
AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(marker, sizeof(*marker));
if (marker->marker == ICC_MARKER && marker->data_length >= ICC_OVERHEAD_LEN)
AVIF_ANNOTATE_MEMORY_IS_INITIALIZED(marker->data, marker->data_length);
return
marker->marker == ICC_MARKER &&
marker->data_length >= ICC_OVERHEAD_LEN &&
Expand Down

0 comments on commit 13428a8

Please sign in to comment.