浏览代码

LibGfx: In webp decoder, check that each transform is used only once

Nico Weber 2 年之前
父节点
当前提交
2fc682c033
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp

+ 8 - 0
Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp

@@ -648,6 +648,8 @@ static ErrorOr<void> decode_webp_chunk_VP8L(WebPLoadingContext& context, Chunk c
     // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#72_structure_of_transforms
 
     // optional-transform   =  (%b1 transform optional-transform) / %b0
+    // "Each transform is allowed to be used only once."
+    u8 seen_transforms = 0;
     while (TRY(bit_stream.read_bits(1))) {
         // transform            =  predictor-tx / color-tx / subtract-green-tx
         // transform            =/ color-indexing-tx
@@ -669,6 +671,12 @@ static ErrorOr<void> decode_webp_chunk_VP8L(WebPLoadingContext& context, Chunk c
         TransformType transform_type = static_cast<TransformType>(TRY(bit_stream.read_bits(2)));
         dbgln_if(WEBP_DEBUG, "transform type {}", (int)transform_type);
 
+        // Check that each transfom is used only once.
+        u8 mask = 1 << (int)transform_type;
+        if (seen_transforms & mask)
+            return context.error("WebPImageDecoderPlugin: transform type used multiple times");
+        seen_transforms |= mask;
+
         switch (transform_type) {
         case PREDICTOR_TRANSFORM:
             return context.error("WebPImageDecoderPlugin: VP8L PREDICTOR_TRANSFORM handling not yet implemented");