avoid libaom crash when encoding >8bpc images at high speed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac3b19f..0c2f749 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
### Changed
- use right-most and bottom-most UV pixels in images with odd-dimensions (ledyba-z)
+- avoid libaom crash when encoding >8bpc images at high speed
## [0.5.5] - 2020-02-13
### Added
diff --git a/src/codec_aom.c b/src/codec_aom.c
index 9344a43..6c325e9 100644
--- a/src/codec_aom.c
+++ b/src/codec_aom.c
@@ -254,6 +254,26 @@
}
}
+ if (image->depth > 8) {
+ // Due to a known issue with libavif v1.0.0-errata1-avif, 10bpc and
+ // 12bpc image encodes will call the wrong variant of
+ // aom_subtract_block when cpu-used is 7 or 8, and crash. Until we get
+ // a new tagged release from libaom with the fix and can verify we're
+ // running with that version of libaom, we must avoid using
+ // cpu-used=7/8 on any >8bpc image encodes.
+ //
+ // Context:
+ // * https://github.com/AOMediaCodec/libavif/issues/49
+ // * https://bugs.chromium.org/p/aomedia/issues/detail?id=2587
+ //
+ // Continued bug tracking here:
+ // * https://github.com/AOMediaCodec/libavif/issues/56
+
+ if (aomCpuUsed > 6) {
+ aomCpuUsed = 6;
+ }
+ }
+
int yShift = 0;
aom_img_fmt_t aomFormat = avifImageCalcAOMFmt(image, alpha, &yShift);
if (aomFormat == AOM_IMG_FMT_NONE) {