Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#3116 closed Patches (wontfix)

boost GIL doesn't properly handle JPEG errors

Reported by: Giel van Schijndel <me@…> Owned by: Hailin Jin
Milestone: Boost 1.40.0 Component: gil USE GITHUB
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc: me@…, mateusz@…

Description

When an error occurs during the decoding of a JPEG file (specifically its header) using jpeg_read_(dimensions|image|view) inside of libjpeg itself the program terminates.

This is because libjpeg uses the error_exit handler from the current jpeg_error_mgr to signal an error. The default error_exit handler simply prints a message to stderr and calls exit(EXIT_FAILURE). However, in order to properly handle this error one needs to override this error_exit handler. Attached patch does just that, using the same error message, though instead, it uses that message as a description for an io_error(const char* desc) generated exception (std::ios_base::failure).

Attachments (1)

jpeg-io_error-exception.patch (751 bytes ) - added by Giel van Schijndel <me@…> 13 years ago.
Turn JPEG errors into exceptions

Download all attachments as: .zip

Change History (5)

by Giel van Schijndel <me@…>, 13 years ago

Turn JPEG errors into exceptions

comment:1 by Giel van Schijndel <me@…>, 13 years ago

Cc: me@… added

PS I'm not entirely sure whether my patch will work properly as it'll end up throwing an exception through C code. Until now, however, I haven't had any problems with throwing through C code though (I'm using it to determine the fileformat employed, i.e. try to load an image until one loader is successful).

The problem is that libjpeg doesn't expect error_exit to return. So another, C-way, of solving this could be by using longjmp and converting to an exception at the jump target.

comment:2 by mloskot <mateusz@…>, 13 years ago

Cc: mateusz@… added

comment:3 by chhenning, 12 years ago

Resolution: wontfix
Status: newclosed

Please use new io extension. A lot of time has been there for correct error handling.

Closing this ticket.

in reply to:  3 comment:4 by pascal@…, 11 years ago

Replying to chhenning:

Please use new io extension. A lot of time has been there for correct error handling.

Which "new extension"? In 1.46 there are still the same old JPEG/TIFF/PNG extensions. Sadly, the JPEG extension is unusable in this state…

Note: See TracTickets for help on using tickets.