Skip to content

Commit

Permalink
TurboJPEG: Handle JERR_BMP*,JERR_PPM* error codes
Browse files Browse the repository at this point in the history
... in tjLoadImage()/tjSaveImage().  These error codes require an add-on
message table, and if it isn't initialized, then format_message()
produces "Bogus message code XXXX" instead.
  • Loading branch information
dcommander committed Jun 12, 2018
1 parent 909a8cf commit 696e754
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ the underlying library, and because it did not involve any out-of-bounds reads
or other exploitable behaviors, it was not believed to represent a security
threat.

3. Fixed an issue whereby the `tjLoadImage()` and `tjSaveImage()` functions
would produce a "Bogus message code" error message if the underlying bitmap and
PPM readers/writers threw an error that was specific to the readers/writers
(as opposed to a general libjpeg API error.)


1.5.90 (2.0 beta1)
==================
Expand Down
12 changes: 12 additions & 0 deletions turbojpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ struct my_error_mgr {
};
typedef struct my_error_mgr *my_error_ptr;

#define JMESSAGE(code, string) string,
static const char *turbojpeg_message_table[] = {
#include "cderror.h"
NULL
};

static void my_error_exit(j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr)cinfo->err;
Expand Down Expand Up @@ -431,6 +437,9 @@ static tjhandle _tjInitCompress(tjinstance *this)
this->jerr.pub.output_message = my_output_message;
this->jerr.emit_message = this->jerr.pub.emit_message;
this->jerr.pub.emit_message = my_emit_message;
this->jerr.pub.addon_message_table = turbojpeg_message_table;
this->jerr.pub.first_addon_message = JMSG_FIRSTADDONCODE;
this->jerr.pub.last_addon_message = JMSG_LASTADDONCODE;

if (setjmp(this->jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
Expand Down Expand Up @@ -1087,6 +1096,9 @@ static tjhandle _tjInitDecompress(tjinstance *this)
this->jerr.pub.output_message = my_output_message;
this->jerr.emit_message = this->jerr.pub.emit_message;
this->jerr.pub.emit_message = my_emit_message;
this->jerr.pub.addon_message_table = turbojpeg_message_table;
this->jerr.pub.first_addon_message = JMSG_FIRSTADDONCODE;
this->jerr.pub.last_addon_message = JMSG_LASTADDONCODE;

if (setjmp(this->jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
Expand Down

0 comments on commit 696e754

Please sign in to comment.