| 80 | } |
| 81 | |
| 82 | static VP8StatusCode ParseRIFF(const uint8_t** const data, size_t* const data_size, |
| 83 | int have_all_data, size_t* const riff_size) { |
| 84 | assert(data != nullptr); |
| 85 | assert(data_size != nullptr); |
| 86 | assert(riff_size != nullptr); |
| 87 | |
| 88 | *riff_size = 0; // Default: no RIFF present. |
| 89 | if (*data_size >= RIFF_HEADER_SIZE && !memcmp(*data, "RIFF", TAG_SIZE)) { |
| 90 | if (memcmp(*data + 8, "WEBP", TAG_SIZE)) { |
| 91 | return VP8_STATUS_BITSTREAM_ERROR; // Wrong image file signature. |
| 92 | } else { |
| 93 | const uint32_t size = GetLE32(*data + TAG_SIZE); |
| 94 | // Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn"). |
| 95 | if (size < TAG_SIZE + CHUNK_HEADER_SIZE) { |
| 96 | return VP8_STATUS_BITSTREAM_ERROR; |
| 97 | } |
| 98 | if (size > MAX_CHUNK_PAYLOAD) { |
| 99 | return VP8_STATUS_BITSTREAM_ERROR; |
| 100 | } |
| 101 | if (have_all_data && (size > *data_size - CHUNK_HEADER_SIZE)) { |
| 102 | return VP8_STATUS_NOT_ENOUGH_DATA; // Truncated bitstream. |
| 103 | } |
| 104 | // We have a RIFF container. Skip it. |
| 105 | *riff_size = size; |
| 106 | *data += RIFF_HEADER_SIZE; |
| 107 | *data_size -= RIFF_HEADER_SIZE; |
| 108 | } |
| 109 | } |
| 110 | return VP8_STATUS_OK; |
| 111 | } |
| 112 | |
| 113 | // Skips to the next VP8/VP8L chunk header in the data given the size of the |
| 114 | // RIFF chunk 'riff_size'. |
no test coverage detected