community/ffmpeg: libswscale bug: sws_scale() returns 0 even on success under certain conditions (aarch64), this breaks telegram-desktop
After investigating why telegram-desktop crashed whenever I would try to view certain stickers, it appears that it uses sws_scale() and checks the return value with an assert, crashing the application if the call fails.
Interestingly enough, removing this assertion did make it work, since the call didn't actually fail, but returned 0 instead of the line count, which can be demonstrated with the following test program: conv_test.c
To compile it:
$ gcc -o conv_test conv_test.c -lswscale -lavutil
Expected result (Debian Buster, x86_64, ffmpeg 4.1.4):
$ ./conv_test
./conv_test: sws_scale() = 32.
./conv_test: Source data:
./conv_test: uint256_t line[0] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
./conv_test: uint128_t line[1] = { 0x80, 0x80, 0x80, 0x7D, 0x80, 0x80, 0x73, 0x6A, 0x7F, 0x82, 0x68, 0x67, 0x80, 0x80, 0x80, 0x80 };
./conv_test: uint128_t line[2] = { 0x80, 0x80, 0x80, 0x7D, 0x80, 0x80, 0x73, 0x6B, 0x7F, 0x82, 0x69, 0x68, 0x80, 0x80, 0x80, 0x80 };
./conv_test: uint0_t line[3] = { };
./conv_test: uint0_t line[4] = { };
./conv_test: uint0_t line[5] = { };
./conv_test: uint0_t line[6] = { };
./conv_test: uint0_t line[7] = { };
./conv_test: Destination data:
./conv_test: uint1024_t line[0] = { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x0F, 0x00, 0xFF, 0x00, 0x0F, 0x00, 0xFF, 0x00, 0x19, 0x00, 0xFF, 0x00, 0x19, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x04, 0x00, 0x03, 0xFF, 0x04, 0x00, 0x03, 0xFF, 0x00, 0x1B, 0x00, 0xFF, 0x00, 0x1B, 0x00, 0xFF, 0x00, 0x1C, 0x00, 0xFF, 0x00, 0x1C, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF };
./conv_test: uint0_t line[1] = { };
./conv_test: uint0_t line[2] = { };
./conv_test: uint0_t line[3] = { };
./conv_test: uint0_t line[4] = { };
./conv_test: uint0_t line[5] = { };
./conv_test: uint0_t line[6] = { };
./conv_test: uint0_t line[7] = { };
$ uname -a
Linux hyper-brodmach 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64 GNU/Linux
Results on aarch64 (pinephone, Alpine Linux (edge, postmarketOS), ffmpeg 4.3):
$ ./conv_test
[swscaler @ 0xaaaadfaf40e0] No accelerated colorspace conversion found from yuv420p to bgra.
./conv_test: sws_scale() = 0.
./conv_test: Source data:
./conv_test: uint256_t line[0] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
./conv_test: uint128_t line[1] = { 0x80, 0x80, 0x80, 0x7D, 0x80, 0x80, 0x73, 0x6A, 0x7F, 0x82, 0x68, 0x67, 0x80, 0x80, 0x80, 0x80 };
./conv_test: uint128_t line[2] = { 0x80, 0x80, 0x80, 0x7D, 0x80, 0x80, 0x73, 0x6B, 0x7F, 0x82, 0x69, 0x68, 0x80, 0x80, 0x80, 0x80 };
./conv_test: uint0_t line[3] = { };
./conv_test: uint0_t line[4] = { };
./conv_test: uint0_t line[5] = { };
./conv_test: uint0_t line[6] = { };
./conv_test: uint0_t line[7] = { };
./conv_test: Destination data:
./conv_test: uint1024_t line[0] = { 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x00, 0xFF, 0x00, 0x10, 0x00, 0xFF, 0x00, 0x1A, 0x00, 0xFF, 0x00, 0x1A, 0x00, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x04, 0x00, 0x03, 0xFF, 0x04, 0x00, 0x03, 0xFF, 0x00, 0x1C, 0x00, 0xFF, 0x00, 0x1C, 0x00, 0xFF, 0x00, 0x1D, 0x00, 0xFF, 0x00, 0x1D, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF };
./conv_test: uint0_t line[1] = { };
./conv_test: uint0_t line[2] = { };
./conv_test: uint0_t line[3] = { };
./conv_test: uint0_t line[4] = { };
./conv_test: uint0_t line[5] = { };
./conv_test: uint0_t line[6] = { };
./conv_test: uint0_t line[7] = { };
$ uname -a
Linux dooshki-pinephone 5.7.0 #1-postmarketos-allwinner SMP Thu Jul 2 11:56:34 UTC 2020 aarch64 GNU/Linux
Edited by Marek Benc