nvjpeg , decode to buffer segment fault

Hi Every one !

I deploy my application in tx2 jetpack 4.2.1.

I use nvjpeg and decodetobuffer to decode jpeg frame,
and I get an segment fault

" Corrupt JPEG data : 1374 extraneous bytes before marker 0xd8 "
" Invalid JPEG file structure : two SOI markers"

How can i ignore it if input jpeg frame is error ?


Please share a patch on 06_jpeg_decode so that we can build,run the app to reproduce the issue. Thanks.

jpg source from camera mjpeg

in my file ccudajpegdecoder.cu
input :

  jpg :host memory 
  jpg_size: sizeof jpg


  bmp : host memory  
  bmp_size : sizeof bmp

I checked byte[0] and byte[1] of jpg input if it 's right 0xff ,0xd8 , i will call this method .

bool CCudaJpegDecoder::cuda_decode(unsigned char* jpg, const int& jpg_size, unsigned char** bmp, int& bmp_size)
    uint32_t width =0;
    uint32_t height =0;
    uint32_t fmt = -1;

    NvJPEGDecoder* dec = (NvJPEGDecoder*)jpegdec;
    NvBuffer* buf = NULL;
                w = width;
                h = height;

I run a few minute -->

" Corrupt JPEG data : 1374 extraneous bytes before marker 0xd8
" Invalid JPEG file structure : two SOI markers"

–> segment fault

Please attach a JPEG file so that we can reproduce it by running below command:

$ /usr/src/tegra_multimedia_api/samples/06_jpeg_decode/jpeg_decode num_files 1 IMAG0561.jpg a.yuv --decode-buffer


./jpeg_decode num_files 1 /home/nvidia/Desktop/test.jpg /home/nvidia/Desktop/a.yuv --decode-buffer
Image Resolution - 768 x 576
munmap_chunk(): invalid pointer
Aborted (core dumped)

i use libturbojpeg to decode jpeg without error.

when i use lib nvjpeg (decodetobuffer) , my program have error after decode many jpeg buffer:

Invalid JPEG file structure: two soi markers

We are checking decoding of the 768x576 image.

For continuous jpeg decoding, please try this

For decoding the 768x576 image. Please try attached patch.
r32_2_TEST_0001-mm_api-jpeg_decode-fix-decoding-failure.zip (1.02 KB)

Thank you for supporting with my questions !

I had used nvjpeg lib you attached.

Can nvjpeg lib ignore it ? it cause crash my app .

The prebuilt lib is to fix an issue in calling decodeToFd(). If you do not call the function, you may ignore the prebuilt lib.

Thank you for your response.

I will try to use it

I found the cause of segment fault . If i check header of jpeg file with lib other lib and feed to decodeToBuffer , that is not segment fault .