| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // WebP container demux. | 10 // WebP container demux. |
| 11 // | 11 // |
| 12 | 12 |
| 13 #ifdef HAVE_CONFIG_H | 13 #ifdef HAVE_CONFIG_H |
| 14 #include "../webp/config.h" | 14 #include "../webp/config.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include <assert.h> | 17 #include <assert.h> |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 #include <string.h> | 19 #include <string.h> |
| 20 | 20 |
| 21 #include "../utils/utils.h" | 21 #include "../utils/utils.h" |
| 22 #include "../webp/decode.h" // WebPGetFeatures | 22 #include "../webp/decode.h" // WebPGetFeatures |
| 23 #include "../webp/demux.h" | 23 #include "../webp/demux.h" |
| 24 #include "../webp/format_constants.h" | 24 #include "../webp/format_constants.h" |
| 25 | 25 |
| 26 #define DMUX_MAJ_VERSION 0 | 26 #define DMUX_MAJ_VERSION 0 |
| 27 #define DMUX_MIN_VERSION 3 | 27 #define DMUX_MIN_VERSION 3 |
| 28 #define DMUX_REV_VERSION 1 | 28 #define DMUX_REV_VERSION 2 |
| 29 | 29 |
| 30 typedef struct { | 30 typedef struct { |
| 31 size_t start_; // start location of the data | 31 size_t start_; // start location of the data |
| 32 size_t end_; // end location | 32 size_t end_; // end location |
| 33 size_t riff_end_; // riff chunk end location, can be > end_. | 33 size_t riff_end_; // riff chunk end location, can be > end_. |
| 34 size_t buf_size_; // size of the buffer | 34 size_t buf_size_; // size of the buffer |
| 35 const uint8_t* buf_; | 35 const uint8_t* buf_; |
| 36 } MemBuffer; | 36 } MemBuffer; |
| 37 | 37 |
| 38 typedef struct { | 38 typedef struct { |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } else { | 583 } else { |
| 584 if (frame->x_offset_ < 0 || frame->y_offset_ < 0) return 0; | 584 if (frame->x_offset_ < 0 || frame->y_offset_ < 0) return 0; |
| 585 if (frame->width_ + frame->x_offset_ > canvas_width) return 0; | 585 if (frame->width_ + frame->x_offset_ > canvas_width) return 0; |
| 586 if (frame->height_ + frame->y_offset_ > canvas_height) return 0; | 586 if (frame->height_ + frame->y_offset_ > canvas_height) return 0; |
| 587 } | 587 } |
| 588 return 1; | 588 return 1; |
| 589 } | 589 } |
| 590 | 590 |
| 591 static int IsValidExtendedFormat(const WebPDemuxer* const dmux) { | 591 static int IsValidExtendedFormat(const WebPDemuxer* const dmux) { |
| 592 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); | 592 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); |
| 593 const int is_fragmented = !!(dmux->feature_flags_ & FRAGMENTS_FLAG); | |
| 594 const Frame* f = dmux->frames_; | 593 const Frame* f = dmux->frames_; |
| 595 | 594 |
| 596 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; | 595 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; |
| 597 | 596 |
| 598 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; | 597 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; |
| 599 if (dmux->loop_count_ < 0) return 0; | 598 if (dmux->loop_count_ < 0) return 0; |
| 600 if (dmux->state_ == WEBP_DEMUX_DONE && dmux->frames_ == NULL) return 0; | 599 if (dmux->state_ == WEBP_DEMUX_DONE && dmux->frames_ == NULL) return 0; |
| 601 if (is_fragmented) return 0; | 600 if (dmux->feature_flags_ & ~ALL_VALID_FLAGS) return 0; // invalid bitstream |
| 602 | 601 |
| 603 while (f != NULL) { | 602 while (f != NULL) { |
| 604 const int cur_frame_set = f->frame_num_; | 603 const int cur_frame_set = f->frame_num_; |
| 605 int frame_count = 0; | 604 int frame_count = 0; |
| 606 | 605 |
| 607 // Check frame properties. | 606 // Check frame properties. |
| 608 for (; f != NULL && f->frame_num_ == cur_frame_set; f = f->next_) { | 607 for (; f != NULL && f->frame_num_ == cur_frame_set; f = f->next_) { |
| 609 const ChunkData* const image = f->img_components_; | 608 const ChunkData* const image = f->img_components_; |
| 610 const ChunkData* const alpha = f->img_components_ + 1; | 609 const ChunkData* const alpha = f->img_components_ + 1; |
| 611 | 610 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 (const char*)iter->chunk.bytes - CHUNK_HEADER_SIZE; | 956 (const char*)iter->chunk.bytes - CHUNK_HEADER_SIZE; |
| 958 return SetChunk(fourcc, iter->chunk_num - 1, iter); | 957 return SetChunk(fourcc, iter->chunk_num - 1, iter); |
| 959 } | 958 } |
| 960 return 0; | 959 return 0; |
| 961 } | 960 } |
| 962 | 961 |
| 963 void WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter) { | 962 void WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter) { |
| 964 (void)iter; | 963 (void)iter; |
| 965 } | 964 } |
| 966 | 965 |
| OLD | NEW |