From 5481acadeda4ea8285839ea8910ee858b9957af4 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 14 Aug 2009 13:18:23 +0000 Subject: [PATCH] GIF metadata extraction fixes: * Fast failure when inconsistencies are detected. * Skip non-GCF, non-application extensions too. * Fix error where seeking was not being done properly for non-netscape application extensions. --- includes/media/GIFMetadataExtractor.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/media/GIFMetadataExtractor.php b/includes/media/GIFMetadataExtractor.php index 1b6589b3a7..0e9c62bf7e 100644 --- a/includes/media/GIFMetadataExtractor.php +++ b/includes/media/GIFMetadataExtractor.php @@ -57,7 +57,7 @@ class GIFMetadataExtractor { // Found a frame $frameCount++; - ## Skip dimensions (Why is this 8 bytes and not 4?) + ## Skip bounding box fread( $fh, 8 ); ## Read BPP @@ -76,6 +76,7 @@ class GIFMetadataExtractor { if ($extension_code == 0xF9) { // Graphics Control Extension. fread( $fh, 1 ); // Block size + fread( $fh, 1 ); // Transparency, disposal method, user input $buf = fread( $fh, 2 ); // Delay, in hundredths of seconds. @@ -99,11 +100,16 @@ class GIFMetadataExtractor { // NETSCAPE2.0 (application name) if ($blockLength != 11 || $data != 'NETSCAPE2.0') { + fseek( $fh, -($blockLength + 1), SEEK_CUR ); self::skipBlock(); continue; } - fread( $fh, 2 ); // Block length and introduction, should be 03 01 + $data = fread( $fh, 2 ); // Block length and introduction, should be 03 01 + + if ($data != "\x03\x01") { + throw new Exception( "Expected \x03\x01, got $data" ); + } // Unsigned little-endian integer, loop count or zero for "forever" $loopData = fread( $fh, 2 ); @@ -116,6 +122,8 @@ class GIFMetadataExtractor { // Read out terminator byte fread( $fh, 1 ); + } else { + self::skipBlock( $fh ); } } elseif ( $buf == self::$gif_term ) { break; @@ -164,4 +172,4 @@ class GIFMetadataExtractor { } } -} \ No newline at end of file +} -- 2.20.1