diff --git a/exifread/core/exif_header.py b/exifread/core/exif_header.py index 0f4c65a..24da23b 100644 --- a/exifread/core/exif_header.py +++ b/exifread/core/exif_header.py @@ -88,9 +88,11 @@ def s2n(self, offset: int, length: int, signed=False) -> int: buf = self.file_handle.read(length) if buf: - # https://github.com/ianare/exif-py/pull/158 - # had to revert as this certain fields to be empty - # please provide test images + # Make sure the buffer is the proper length. + # Allows bypassing of corrupt slices. + if len(buf) != length: + logger.warning("Unexpected slice length: %d", len(buf)) + return 0 return struct.unpack(fmt, buf)[0] return 0 diff --git a/tests/resources/dump.txt b/tests/resources/dump.txt index 4b8b970..7865ab5 100644 --- a/tests/resources/dump.txt +++ b/tests/resources/dump.txt @@ -3475,7 +3475,7 @@ Thumbnail ResolutionUnit (Short): Pixels/Inch Thumbnail XResolution (Ratio): 1 Thumbnail YResolution (Ratio): 1 -Opening: tests/resources/jpg/sony_alpha_a58.JPG +Opening: tests/resources/jpg/Sony_alpha_a58.JPG File has JPEG thumbnail EXIF BrightnessValue (Signed Ratio): -1543/1280 EXIF ColorSpace (Short): sRGB @@ -3543,6 +3543,65 @@ Thumbnail XResolution (Signed Long): 72 Thumbnail YCbCrPositioning (Short): Co-sited Thumbnail YResolution (Signed Long): 72 +Opening: tests/resources/jpg/Sony_DSLR-A200.jpg +File has JPEG thumbnail +EXIF BrightnessValue (Signed Ratio): 387/100 +EXIF ColorSpace (Short): sRGB +EXIF ComponentsConfiguration (Undefined): YCbCr +EXIF CompressedBitsPerPixel (Ratio): 8 +EXIF Contrast (Short): Normal +EXIF CustomRendered (Short): Normal +EXIF DateTimeDigitized (ASCII): 2007:01:01 00:00:00 +EXIF DateTimeOriginal (ASCII): 2007:01:01 00:00:00 +EXIF ExifImageLength (Long): 2463 +EXIF ExifImageWidth (Long): 1391 +EXIF ExifVersion (Undefined): 0221 +EXIF ExposureBiasValue (Signed Ratio): 0 +EXIF ExposureMode (Short): Auto Exposure +EXIF ExposureProgram (Short): Program Normal +EXIF ExposureTime (Ratio): 1/60 +EXIF FNumber (Ratio): 28/5 +EXIF FileSource (Undefined): Digital Camera +EXIF Flash (Short): Flash fired, auto mode +EXIF FlashPixVersion (Undefined): 0100 +EXIF FocalLength (Ratio): 26 +EXIF FocalLengthIn35mmFilm (Short): 39 +EXIF ISOSpeedRatings (Short): 400 +EXIF ImageUniqueID (ASCII): 5eb7c1ccbf663e54ed89e0fbc4026c84 +EXIF InteroperabilityOffset (Long): 5868 +EXIF LightSource (Short): Unknown +EXIF MakerNote (Undefined): [83, 79, 78, 89, 32, 68, 83, 67, 32, 0, 0, 0, 19, 0, 24, 0, 7, 0, 0, 16, ... ] +EXIF MaxApertureValue (Ratio): 217/50 +EXIF MeteringMode (Short): Pattern +EXIF Saturation (Short): Normal +EXIF SceneCaptureType (Short): Standard +EXIF SceneType (Undefined): Directly Photographed +EXIF Sharpness (Short): Normal +EXIF UserComment (Undefined): +EXIF WhiteBalance (Short): Auto +Image Artist (ASCII): Picasa +Image DateTime (ASCII): 2014:02:03 21:15:18 +Image ExifOffset (Long): 366 +Image ImageDescription (ASCII): SONY DSC +Image Make (ASCII): SONY +Image Model (ASCII): DSLR-A200 +Image PrintIM (Undefined): [80, 114, 105, 110, 116, 73, 77, 0, 48, 51, 48, 48, 0, 0, 6, 0, 1, 0, 22, 0, ... ] +Image ResolutionUnit (Short): Pixels/Inch +Image Software (ASCII): DSLR-A200 v1.00 +Image XResolution (Ratio): 72 +Image YCbCrPositioning (Short): Co-sited +Image YResolution (Ratio): 72 +Interoperability InteroperabilityIndex (ASCII): R98 +Interoperability InteroperabilityVersion (Undefined): [48, 49, 48, 48] +Interoperability RelatedImageLength (Long): 2592 +Interoperability RelatedImageWidth (Long): 3872 +Thumbnail Compression (Short): JPEG (old-style) +Thumbnail JPEGInterchangeFormat (Long): 6016 +Thumbnail JPEGInterchangeFormatLength (Long): 3578 +Thumbnail ResolutionUnit (Short): Pixels/Inch +Thumbnail XResolution (Ratio): 72 +Thumbnail YResolution (Ratio): 72 + Opening: tests/resources/jpg/Sony_HDR-HC3.jpg File has JPEG thumbnail EXIF ColorSpace (Short): sRGB diff --git a/tests/resources/jpg/README b/tests/resources/jpg/README index 1c642d0..eba49f1 100644 --- a/tests/resources/jpg/README +++ b/tests/resources/jpg/README @@ -27,13 +27,14 @@ Ricoh_Caplio_RR330.jpg Steveston_dusk.JPG Samsung_Digimax_i50_MP3.jpg Villa_di_Poggio_a_Caiano,_sala_neoclassica_4.JPG Sony_HDR-HC3.jpg Positive_roll_film.jpg WWL_(Polaroid)_ION230.jpg PoudriereBoisSousRoche3.jpg +Sony_DSLR-A200.jpg Aloe_Vera_Flower.jpg = Other Stuff = long_description.jpg US_10th_Mountain_Division_soldiers_in_Afghanistan.jpg -Contributions : +Contributions: PaintTool_sample.jpg -- Submitted by Jan Trofimov (OXIj) diff --git a/tests/resources/jpg/Sony_DSLR-A200.jpg b/tests/resources/jpg/Sony_DSLR-A200.jpg new file mode 100644 index 0000000..436b269 Binary files /dev/null and b/tests/resources/jpg/Sony_DSLR-A200.jpg differ diff --git a/tests/resources/jpg/sony_alpha_a58.JPG b/tests/resources/jpg/Sony_alpha_a58.JPG similarity index 100% rename from tests/resources/jpg/sony_alpha_a58.JPG rename to tests/resources/jpg/Sony_alpha_a58.JPG