Crash in dav1d_data_wrap on 32-bit x86 when called by libavif
All dav1d tests pass but some libavif tests fail when dav1d is built by Clang >= 12. GCC isn't affected. Possible workarounds are adding -O0
or applying the following:
diff --git a/src/lib.c b/src/lib.c
index 8f0b75a..dbaa771 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -745,6 +745,9 @@ uint8_t *dav1d_data_create(Dav1dData *const buf, const size_t sz) {
return dav1d_data_create_internal(buf, sz);
}
+#ifdef __i386__
+__attribute__((optnone))
+#endif
int dav1d_data_wrap(Dav1dData *const buf, const uint8_t *const ptr,
const size_t sz,
void (*const free_callback)(const uint8_t *data,
$ cc --version
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: i386-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin
$ git clone https://github.com/AOMediaCodec/libavif
$ git clone https://code.videolan.org/videolan/dav1d libavif/ext/dav1d
$ meson setup --buildtype=debugoptimized --default-library=static libavif/ext/dav1d/build libavif/ext/dav1d
$ meson compile -C libavif/ext/dav1d/build
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=OFF -DAVIF_BUILD_TESTS=ON -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON -G Ninja -B libavif_build -S libavif
$ cmake --build libavif_build
$ ctest --test-dir libavif_build
[...]
55% tests passed, 5 tests failed out of 11
Total Test time (real) = 17.33 sec
The following tests FAILED:
1 - aviftest (Bus error)
4 - avifallocationtest (Failed)
6 - avifgridapitest (Failed)
7 - avifincrtest (Bus error)
8 - avifmetadatatest (Failed)
$ libavif_build/tests/aviftest libavif/tests/data/
Codec Versions: dav1d [dec]:1.0.0
Test Data Dir : libavif/tests/data/
AVIF Test Suite: Running IO Tests...
File: [cosmos1650_yuv444_10bpc_p3pq.avif @ 274 / 37451 bytes, Persistent, IgnoreMetadata] parse returned: OK
Bus error
* thread #1, name = 'aviftest', stop reason = signal SIGBUS: hardware error
frame #0: 0x0044ee96 aviftest`dav1d_data_wrap(buf=0xffffca00, ptr="\U00000012", sz=37169, free_callback=(aviftest`avifDav1dFreeCallback at codec_dav1d.c:34), user_data=0x00000000) at lib.c:753
750 void (*const free_callback)(const uint8_t *data,
751 void *user_data),
752 void *const user_data)
-> 753 {
754 return dav1d_data_wrap_internal(buf, ptr, sz, free_callback, user_data);
755 }
756
(lldb) bt
* thread #1, name = 'aviftest', stop reason = signal SIGBUS: hardware error
* frame #0: 0x0044ee96 aviftest`dav1d_data_wrap(buf=0xffffca00, ptr="\U00000012", sz=37169, free_callback=(aviftest`avifDav1dFreeCallback at codec_dav1d.c:34), user_data=0x00000000) at lib.c:753
frame #1: 0x0044d8f9 aviftest`dav1dCodecGetNextImage(codec=0x207e9090, decoder=0x207e2000, sample=0x207e9060, alpha=0, isLimitedRangeAlpha=0xffffca68, image=0x20a000a0) at codec_dav1d.c:87:9
frame #2: 0x0044217b aviftest`avifDecoderDecodeTiles(decoder=<unavailable>, nextImageIndex=<unavailable>, firstTileIndex=0, tileCount=1, decodedTileCount=0x207ec02c) at read.c:3853:14
frame #3: 0x00441f14 aviftest`avifDecoderNextImage(decoder=0x207e2000) at read.c:3937:9
frame #4: 0x0043b71a aviftest`main at aviftest.c:255:54
frame #5: 0x0043b445 aviftest`main(argc=2, argv=0xffffdc78) at aviftest.c:327:19
frame #6: 0x0043b12d aviftest`_start1(cleanup=0x2054d7e0, argc=2, argv=0xffffdc78) at crt1_c.c:72:7
frame #7: 0x0043b290 aviftest`_start at crt1_s.S:46
Edited by Jan Beich