mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 18:35:41 +01:00 
			
		
		
		
	improve VP8L signature detection by checking the version bits too
Change-Id: I20bea00b9582d7ea8c7b643616c78f717ce1bdf2
This commit is contained in:
		| @@ -84,20 +84,19 @@ static int DecodeImageStream(int xsize, int ysize, | ||||
| //------------------------------------------------------------------------------ | ||||
|  | ||||
| int VP8LCheckSignature(const uint8_t* const data, size_t size) { | ||||
|   return (size >= 1) && (data[0] == VP8L_MAGIC_BYTE); | ||||
|   return (size >= VP8L_FRAME_HEADER_SIZE && | ||||
|           data[0] == VP8L_MAGIC_BYTE && | ||||
|           (data[4] >> 5) == 0);  // version | ||||
| } | ||||
|  | ||||
| static int ReadImageInfo(VP8LBitReader* const br, | ||||
|                          int* const width, int* const height, | ||||
|                          int* const has_alpha) { | ||||
|   const uint8_t signature = VP8LReadBits(br, 8); | ||||
|   if (!VP8LCheckSignature(&signature, 1)) { | ||||
|     return 0; | ||||
|   } | ||||
|   if (VP8LReadBits(br, 8) != VP8L_MAGIC_BYTE) return 0; | ||||
|   *width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1; | ||||
|   *height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1; | ||||
|   *has_alpha = VP8LReadBits(br, 1); | ||||
|   VP8LReadBits(br, VP8L_VERSION_BITS);  // Read/ignore the version number. | ||||
|   if (VP8LReadBits(br, VP8L_VERSION_BITS) != 0) return 0; | ||||
|   return 1; | ||||
| } | ||||
|  | ||||
| @@ -105,6 +104,8 @@ int VP8LGetInfo(const uint8_t* data, size_t data_size, | ||||
|                 int* const width, int* const height, int* const has_alpha) { | ||||
|   if (data == NULL || data_size < VP8L_FRAME_HEADER_SIZE) { | ||||
|     return 0;         // not enough data | ||||
|   } else if (!VP8LCheckSignature(data, data_size)) { | ||||
|     return 0;         // bad signature | ||||
|   } else { | ||||
|     int w, h, a; | ||||
|     VP8LBitReader br; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user