Bug (misfeature?) in SDL_Image-1.2.0

The following code in IMG_LoadTyped_RW(), called from IMG_Load(),
attempts to determine the image type of a file. However, if the first
test, the function call to the individual supported file type
detection routine:

    supported[i].is(src)

fails, it then “assumes” that the extension on the filename provides
enough information to open the file. If the filename has a ".jpg"
extension, and that file is inadvertently empty, libjpeg.a detects
that the file isn’t a jpeg, and exits (i.e. it doesn’t just print
the a message, it really exits!) following the message, “Not a JPEG
file: starts with 0xff 0xd9”. (Not that it doesn’t start with 0xff
0xd9; the file was really empty.)

I’m trying to determine the best way to solve this problem. Should
the following code contain a test for zero length? Should it contain
a test for some non-zero minimum length? Should I just remove the
extension test so if the detection routine doesn’t say it’s the proper
type of file then don’t assume it’s this type of image?

Why would one want to call the load() function for an image type for
which we’ve already determined that the file is not of that type? Is
there some valid time that one might want to do that?

I think this is a sufficiently generic problem that something
belongs in here; I don’t think that the caller should have to
ascertain that the image is valid prior to calling IMG_Load().

Here’s the relevant code from IMG_LoadTyped_RW():

/* Detect the type of image being loaded */
start = SDL_RWtell(src);
image = NULL;
for ( i=0; i < ARRAYSIZE(supported); ++i ) {
        if( (supported[i].is
	     && (SDL_RWseek(src, start, SEEK_SET),
		 supported[i].is(src)))
	    || (type && IMG_string_equals(type, supported[i].type))) {

#ifdef DEBUG_IMGLIB
fprintf(stderr, “IMGLIB: Loading image as %s\n”,
supported[i].type);
#endif
SDL_RWseek(src, start, SEEK_SET);
image = supported[i].load(src);
break;
}
}

Ideas?

Cheers,

Derrell

Derrell.Lipman at UnwiredUniverse.com wrote:

However, if the first
test, the function call to the individual supported file type
detection routine:

   supported[i].is(src)

fails, it then “assumes” that the extension on the filename provides
enough information to open the file.

it’s a bug. I’ll fix it, no worry

(in general, SDL_image isn’t entirely stable when given mislabeled files
and/or nonexistent/damaged files. it’s a known problem)