]> mj.ucw.cz Git - libucw.git/blobdiff - images/io-libjpeg.c
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git#dev-threads
[libucw.git] / images / io-libjpeg.c
index 30bd0fff4b90061f16a135a275e7bbd2c9a73634..1d3d37c5029e046212bee97f484179b50bea9391 100644 (file)
@@ -135,7 +135,11 @@ libjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
         {
          num_bytes -= i->src.bytes_in_buffer;
          libjpeg_fastbuf_read_commit(i);
-         bskip(i->fastbuf, num_bytes);
+         if (!bskip(i->fastbuf, num_bytes))
+           {
+             IMAGE_ERROR(i->err.io->context, IMAGE_ERROR_READ_FAILED, "Incomplete JPEG file");
+             longjmp(i->err.setjmp_buf, 1);
+           }
          libjpeg_fastbuf_read_prepare(i);
        }
     }
@@ -181,8 +185,6 @@ libjpeg_empty_output_buffer(j_compress_ptr cinfo)
   return TRUE;
 }
 
-#ifdef CONFIG_IMAGES_EXIF
-
 static inline uns
 libjpeg_read_byte(struct libjpeg_read_internals *i)
 {
@@ -219,7 +221,8 @@ libjpeg_app1_preprocessor(j_decompress_ptr cinfo)
 {
   struct libjpeg_read_internals *i = (struct libjpeg_read_internals *)cinfo;
   struct image_io *io = i->err.io;
-  uns len = (libjpeg_read_byte(i) << 8) + libjpeg_read_byte(i);
+  uns len = libjpeg_read_byte(i) << 8;
+  len += libjpeg_read_byte(i);
   DBG("Found APP1 marker, len=%u", len);
   if (len < 2)
     return TRUE;
@@ -244,8 +247,6 @@ libjpeg_app1_preprocessor(j_decompress_ptr cinfo)
   return TRUE;
 }
 
-#endif
-
 static void
 libjpeg_read_cancel(struct image_io *io)
 {
@@ -283,10 +284,8 @@ libjpeg_read_header(struct image_io *io)
   i->src.resync_to_restart = jpeg_resync_to_restart;
   i->src.term_source = libjpeg_term_source;
 
-#ifdef CONFIG_IMAGES_EXIF
   if (io->flags & IMAGE_IO_WANT_EXIF)
     jpeg_set_marker_processor(&i->cinfo, JPEG_APP0 + 1, libjpeg_app1_preprocessor);
-#endif
 
   /* Read JPEG header and setup decompression options */
   DBG("Reading image header");
@@ -475,7 +474,6 @@ libjpeg_write(struct image_io *io)
   jpeg_set_defaults(&i.cinfo);
   if (io->jpeg_quality)
     jpeg_set_quality(&i.cinfo, MIN(io->jpeg_quality, 100), 1);
-#ifdef CONFIG_IMAGES_EXIF
   if (io->exif_size)
     {
       /* According to the Exif specification, the Exif APP1 marker has to follow immediately after the SOI,
@@ -484,17 +482,14 @@ libjpeg_write(struct image_io *io)
       i.cinfo.write_JFIF_header = FALSE;
       i.cinfo.write_Adobe_marker = FALSE;
     }
-#endif
 
   /* Compress the image */
   jpeg_start_compress(&i.cinfo, TRUE);
-#ifdef CONFIG_IMAGES_EXIF
   if (io->exif_size)
     {
       DBG("Writing EXIF");
       jpeg_write_marker(&i.cinfo, JPEG_APP0 + 1, io->exif_data, io->exif_size);
     }
-#endif
   switch (img->pixel_size)
     {
       /* grayscale or RGB */