@@ -448,26 +448,31 @@ gpujpeg_reader_read_spiff_header(uint8_t** image, int verbose, enum gpujpeg_colo
448448static int
449449gpujpeg_reader_read_spiff_directory (uint8_t * * image , const uint8_t * image_end , int verbose , int length , _Bool * in_spiff )
450450{
451- if (length < 4 ) {
452- fprintf ( stderr , "[GPUJPEG] [Error] APP8 SPIFF directory too short (%d bytes)\n" , length + 2 );
453- image += length ;
451+ if ( length < 8 ) { // ELEN at least 8
452+ ERROR_MSG ( " APP8 SPIFF directory too short (%d bytes)\n" , length );
453+ image += length - 2 ;
454454 return -1 ;
455455 }
456456 uint32_t tag = gpujpeg_reader_read_4byte (* image );
457- DEBUG2_MSG (verbose , "Read SPIFF tag 0x%x with length %d.\n" , tag , length + 2 );
458- if (tag == SPIFF_ENTRY_TAG_EOD && length == SPIFF_ENTRY_TAG_EOD_LENGHT - 2 ) {
457+ DEBUG2_MSG (verbose , "Read SPIFF tag 0x%x with length %d.\n" , tag , length );
458+ if ( tag == SPIFF_ENTRY_TAG_EOD && length == SPIFF_ENTRY_TAG_EOD_LENGHT ) {
459459 int marker_soi = gpujpeg_reader_read_marker (image , image_end , verbose );
460460 if ( marker_soi != GPUJPEG_MARKER_SOI ) {
461461 VERBOSE_MSG (verbose , "SPIFF entry 0x1 should be followed directly with SOI.\n" );
462462 return -1 ;
463463 }
464464 DEBUG2_MSG (verbose , "SPIFF EOD presented.\n" );
465465 * in_spiff = 0 ;
466- } else if (tag >> 24U != 0 ) {
466+ return 0 ;
467+ }
468+
469+ if ( tag >> 24U != 0 ) { // given by the standard
467470 VERBOSE_MSG (verbose , "Erroneous SPIFF tag 0x%x (first byte should be 0)." , tag );
468- } else {
469- DEBUG2_MSG ( verbose , "SPIFF tag 0x%x with length %d presented.\n" , tag , length + 2 ) ;
471+ * image += length - 6 ;
472+ return 0 ;
470473 }
474+ DEBUG2_MSG (verbose , "SPIFF tag 0x%x with length %d presented.\n" , tag , length );
475+ * image += length - 6 ;
471476 return 0 ;
472477}
473478
@@ -497,7 +502,7 @@ gpujpeg_reader_read_app8(uint8_t** image, const uint8_t* image_end, enum gpujpeg
497502 }
498503
499504 if (* in_spiff ) {
500- return gpujpeg_reader_read_spiff_directory (image , image_end , verbose , length , in_spiff );
505+ return gpujpeg_reader_read_spiff_directory (image , image_end , verbose , length + 2 , in_spiff );
501506 }
502507
503508 if (length + 2 != SPIFF_MARKER_LEN ) {
0 commit comments