Skip to content

Commit

Permalink
SDL_image shouldn't dereference a rwops if it's NULL.
Browse files Browse the repository at this point in the history
  Fixes Bugzilla #284.
  • Loading branch information
icculus committed Feb 13, 2007
1 parent 530c15d commit 9a40616
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions IMG_bmp.c
Expand Up @@ -36,6 +36,8 @@ int IMG_isBMP(SDL_RWops *src)
int is_BMP;
char magic[2];

if ( !src )
return 0;
start = SDL_RWtell(src);
is_BMP = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
Expand Down
2 changes: 2 additions & 0 deletions IMG_gif.c
Expand Up @@ -36,6 +36,8 @@ int IMG_isGIF(SDL_RWops *src)
int is_GIF;
char magic[6];

if ( !src )
return 0;
start = SDL_RWtell(src);
is_GIF = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
Expand Down
2 changes: 2 additions & 0 deletions IMG_jpg.c
Expand Up @@ -179,6 +179,8 @@ int IMG_isJPG(SDL_RWops *src)
/* Blame me, not Sam, if this doesn't work right. */
/* And don't forget to report the problem to the the sdl list too! */

if ( !src )
return 0;
start = SDL_RWtell(src);
is_JPG = 0;
in_scan = 0;
Expand Down
2 changes: 2 additions & 0 deletions IMG_lbm.c
Expand Up @@ -65,6 +65,8 @@ int IMG_isLBM( SDL_RWops *src )
int is_LBM;
Uint8 magic[4+4+4];

if ( !src )
return 0;
start = SDL_RWtell(src);
is_LBM = 0;
if ( SDL_RWread( src, magic, sizeof(magic), 1 ) )
Expand Down
2 changes: 2 additions & 0 deletions IMG_pcx.c
Expand Up @@ -69,6 +69,8 @@ int IMG_isPCX(SDL_RWops *src)
const int PCX_RunLength_Encoding = 1;
struct PCXheader pcxh;

if ( !src )
return 0;
start = SDL_RWtell(src);
is_PCX = 0;
if ( SDL_RWread(src, &pcxh, sizeof(pcxh), 1) == 1 ) {
Expand Down
2 changes: 2 additions & 0 deletions IMG_png.c
Expand Up @@ -273,6 +273,8 @@ int IMG_isPNG(SDL_RWops *src)
if ( IMG_InitPNG() < 0 ) {
return 0;
}
if ( !src )
return 0;
start = SDL_RWtell(src);
is_PNG = 0;
if ( SDL_RWread(src, buf, 1, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK ) {
Expand Down
2 changes: 2 additions & 0 deletions IMG_pnm.c
Expand Up @@ -44,6 +44,8 @@ int IMG_isPNM(SDL_RWops *src)
int is_PNM;
char magic[2];

if ( !src )
return 0;
start = SDL_RWtell(src);
is_PNM = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
Expand Down
2 changes: 2 additions & 0 deletions IMG_tif.c
Expand Up @@ -174,6 +174,8 @@ int IMG_isTIF(SDL_RWops* src)
if ( IMG_InitTIF() < 0 ) {
return 0;
}
if ( !src )
return 0;
start = SDL_RWtell(src);
is_TIF = 0;

Expand Down
2 changes: 2 additions & 0 deletions IMG_xcf.c
Expand Up @@ -213,6 +213,8 @@ int IMG_isXCF(SDL_RWops *src)
int is_XCF;
char magic[14];

if ( !src )
return 0;
start = SDL_RWtell(src);
is_XCF = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
Expand Down
8 changes: 6 additions & 2 deletions IMG_xpm.c
Expand Up @@ -59,6 +59,8 @@ int IMG_isXPM(SDL_RWops *src)
int is_XPM;
char magic[9];

if ( !src )
return 0;
start = SDL_RWtell(src);
is_XPM = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
Expand Down Expand Up @@ -326,7 +328,8 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src)
linebuf = NULL;
buflen = 0;

start = SDL_RWtell(src);
if ( src )
start = SDL_RWtell(src);

if(xpm)
xpmlines = &xpm;
Expand Down Expand Up @@ -453,7 +456,8 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src)

done:
if(error) {
SDL_RWseek(src, start, SEEK_SET);
if ( src )
SDL_RWseek(src, start, SEEK_SET);
if ( image ) {
SDL_FreeSurface(image);
image = NULL;
Expand Down
2 changes: 2 additions & 0 deletions IMG_xv.c
Expand Up @@ -89,6 +89,8 @@ int IMG_isXV(SDL_RWops *src)
int is_XV;
int w, h;

if ( !src )
return 0;
start = SDL_RWtell(src);
is_XV = 0;
if ( get_header(src, &w, &h) == 0 ) {
Expand Down
2 changes: 2 additions & 0 deletions IMG_xxx.c
Expand Up @@ -34,6 +34,8 @@ int IMG_isXXX(SDL_RWops *src)
int start;
int is_XXX;

if ( !src )
return 0;
start = SDL_RWtell(src);
is_XXX = 0;

Expand Down

0 comments on commit 9a40616

Please sign in to comment.