Opened 3 years ago

Last modified 13 months ago

#11314 new Bugs

boost::gil::jpeg_read_dimensions(const char*) does not throw exceptions as it should

Reported by: anonymous Owned by: Stefan Seefeld
Milestone: To Be Determined Component: gil USE GITHUB
Version: Boost 1.58.0 Severity: Problem
Keywords: libjpeg Cc: mateusz@…


boost::gil::jpeg_read_dimensions(const char*) is documented as followed (resides in .../boost/gil/extension/io/jpeg_io.hpp):

/// \ingroup JPEG_IO
/// \brief Returns the width and height of the JPEG file at the specified location.
/// Throws std::ios_base::failure if the location does not correspond to a valid JPEG file

However, it does not always throw an exception. Instead it prints an error message and exits the program, which is how libjpeg by default handle its errors.

See the following code:

#include <iostream>

#include <boost/gil/extension/io/jpeg_io.hpp>

using std::cout;
using std::cerr;
using std::endl;
using std::ios_base;

namespace gil = boost::gil;

int main(int argc, char **argv) {
  if(argc != 2) {
    cerr << "Please supply a file name." << endl;
    return 1;

  const char *file = argv[1];

  cout << file << ": " << endl;

  try {
  } catch(const ios_base::failure &ib_f) {
    cerr << "what: " << ib_f.what() << endl;
  } catch(...) {
    cerr << "caught other exception!" << endl;

  cout << "\nDone." << endl;

  return 0;

I compile it using g++ 4.9.2 using the options

-std=c++11 -I/usr/local/include -L/usr/local/lib -ljpeg -o bin main.cpp

on a Mac OS X 10.9.5.

See these three runs:

$ ./bin non_existing.jpeg # this file does not exist
what: file_mgr: failed to open file

$ ./bin existing_empty.jpeg # this file exist but is empty
Empty input file
$ ./bin existing_non_jpeg.jpeg # this file exist and is not empty, but is not a jpeg
Not a JPEG file: starts with 0x62 0x6c

Attachments (0)

Change History (2)

comment:1 Changed 17 months ago by Mateusz Loskot

Cc: mateusz@… added

comment:2 Changed 13 months ago by Stefan Seefeld

Owner: changed from Hailin Jin to Stefan Seefeld

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain Stefan Seefeld.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.