Changeset 12383
- Timestamp:
- 10/12/07 16:29:29 (1 year ago)
- Files:
-
- branches/1.4/gdal/frmts/jpeg/jpgdataset.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.4/gdal/frmts/jpeg/jpgdataset.cpp
r12087 r12383 398 398 /* Read number of entry in directory */ 399 399 /* -------------------------------------------------------------------- */ 400 VSIFSeekL(fp, nOffset+nTIFFHEADER, SEEK_SET);401 402 if(VSIFReadL(&nEntryCount,1,sizeof(GUInt16),fp) != sizeof(GUInt16))400 if( VSIFSeekL(fp, nOffset+nTIFFHEADER, SEEK_SET) != 0 401 || VSIFReadL(&nEntryCount,1,sizeof(GUInt16),fp) != sizeof(GUInt16) ) 402 { 403 403 CPLError( CE_Failure, CPLE_AppDefined, 404 "Error directory count"); 404 "Error reading EXIF Directory count at %d.", 405 nOffset + nTIFFHEADER ); 406 return CE_Failure; 407 } 405 408 406 409 if (bSwabflag) … … 411 414 return CE_None; 412 415 416 // Some files are corrupt, a large entry count is a sign of this. 417 if( nEntryCount > 125 ) 418 { 419 CPLError( CE_Warning, CPLE_AppDefined, 420 "Ignoring EXIF directory with unlikely entry count (%d).", 421 nEntryCount ); 422 return CE_Warning; 423 } 424 413 425 poTIFFDir = (TIFFDirEntry *)CPLMalloc(nEntryCount * sizeof(TIFFDirEntry)); 414 426 415 427 if (poTIFFDir == NULL) 428 { 416 429 CPLError( CE_Failure, CPLE_AppDefined, 417 430 "No space for TIFF directory"); 431 return CE_Failure; 432 } 418 433 419 434 /* -------------------------------------------------------------------- */ … … 422 437 n = VSIFReadL(poTIFFDir, 1,nEntryCount*sizeof(TIFFDirEntry),fp); 423 438 if (n != nEntryCount*sizeof(TIFFDirEntry)) 439 { 424 440 CPLError( CE_Failure, CPLE_AppDefined, 425 441 "Could not read all directories"); 442 return CE_Failure; 443 } 426 444 427 445 /* -------------------------------------------------------------------- */ … … 440 458 /* -------------------------------------------------------------------- */ 441 459 pszName[0] = '\0'; 460 pszTemp[0] = '\0'; 442 461 443 462 for (poExifTags = tagnames; poExifTags->tag; poExifTags++) … … 560 579 /* The data is being read where tdir_offset point to in the file */ 561 580 /* -------------------------------------------------------------------- */ 562 else {563 581 else if (space > 0 && space < MAXSTRINGLENGTH) 582 { 564 583 unsigned char *data = (unsigned char *)CPLMalloc(space); 565 584 … … 602 621 } 603 622 } 623 else 624 { 625 CPLError( CE_Warning, CPLE_AppDefined, 626 "Invalid EXIF header size: %ld, ignoring tag.", space ); 627 } 628 604 629 papszMetadata = CSLSetNameValue(papszMetadata, pszName, pszTemp); 605 630 }
