[FFmpeg-trac] #9985(swscale:new): Flipping an image with sws_scale crashes in arm64

FFmpeg trac at avcodec.org
Fri Oct 21 19:50:55 EEST 2022


#9985: Flipping an image with sws_scale crashes in arm64
---------------------------------+--------------------------------------
             Reporter:  diogo.r  |                     Type:  defect
               Status:  new      |                 Priority:  normal
            Component:  swscale  |                  Version:  git-master
             Keywords:           |               Blocked By:
             Blocking:           |  Reproduced by developer:  0
Analyzed by developer:  0        |
---------------------------------+--------------------------------------
 Summary of the bug:

 Not sure if this is a bug, or if I'm just using the API in a way it was
 not meant to be used. I'm trying to convert and flip an image with
 sws_scale. From my tests, this works perfectly fine in windows and macos-
 x86_64, but blows up in macos-arm64. I've reproduced it with ffmpeg 5.1.1


 How to reproduce:

 Compile and run this on a mac with a new arm64 M1 processor, it should
 crash every time.


 {{{
 extern "C"
 {
         #include <libswscale/swscale.h>
 }

 int main() {
     const int planes = 8;
     const int width = 720;
     const int height = 480;
     const int padding = 0;

     AVPixelFormat srcFormat = AVPixelFormat::AV_PIX_FMT_YUV420P;
     int srcStride[planes] = {
         padding + width,
         padding + width / 2,
         padding + width / 2
     };

     uint8_t *src[planes] = {
         new uint8_t[srcStride[0] * height],
         new uint8_t[srcStride[1] * height],
         new uint8_t[srcStride[2] * height],
     };

     AVPixelFormat dstFormat = AVPixelFormat::AV_PIX_FMT_BGRA;
     int dstStride[planes] = {
         padding + width * 4
     };

     uint8_t *dst[planes] = {
         new uint8_t[dstStride[0] * height]
     };

     struct SwsContext* sws_ctx = sws_getContext(
         width,
         height,
         srcFormat,
         width,
         height,
         dstFormat,
         SWS_BILINEAR,
         NULL,
         NULL,
         NULL
     );

     // Flip image
     dst[0] = dst[0] + (height - 1) * dstStride[0];
     dstStride[0] = -dstStride[0];

     sws_scale(
         sws_ctx,
         src,
         srcStride,
         0,
         height,
         dst,
         dstStride
     );
 }
 }}}

 Thanks for the help, and for your efforts to develop such a cool project :
 )
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/9985>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list