Merge changes If39ab7f5,I3658b5ae

* changes:
  WebPMuxCreate() error handling:
  Fix a memleak in WebPMuxCreate()
This commit is contained in:
pascal massimino 2012-07-02 01:46:17 -07:00 committed by Gerrit Code Review
commit 4691407bb3

View File

@ -85,23 +85,25 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
WebPMuxImage* wpi = NULL; WebPMuxImage* wpi = NULL;
const uint8_t* data; const uint8_t* data;
size_t size; size_t size;
WebPChunk chunk;
ChunkInit(&chunk);
// Sanity checks. // Sanity checks.
if (version != WEBP_MUX_ABI_VERSION) goto Err; // version mismatch if (version != WEBP_MUX_ABI_VERSION) return NULL; // version mismatch
if (bitstream == NULL) goto Err; if (bitstream == NULL) return NULL;
data = bitstream->bytes_; data = bitstream->bytes_;
size = bitstream->size_; size = bitstream->size_;
if (data == NULL) goto Err; if (data == NULL) return NULL;
if (size < RIFF_HEADER_SIZE) return NULL; if (size < RIFF_HEADER_SIZE) return NULL;
if (GetLE32(data + 0) != mktag('R', 'I', 'F', 'F') || if (GetLE32(data + 0) != mktag('R', 'I', 'F', 'F') ||
GetLE32(data + CHUNK_HEADER_SIZE) != mktag('W', 'E', 'B', 'P')) { GetLE32(data + CHUNK_HEADER_SIZE) != mktag('W', 'E', 'B', 'P')) {
goto Err; return NULL;
} }
mux = WebPMuxNew(); mux = WebPMuxNew();
if (mux == NULL) goto Err; if (mux == NULL) return NULL;
if (size < RIFF_HEADER_SIZE + TAG_SIZE) goto Err; if (size < RIFF_HEADER_SIZE + TAG_SIZE) goto Err;
@ -132,10 +134,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
// Loop over chunks. // Loop over chunks.
while (data != end) { while (data != end) {
WebPChunkId id; WebPChunkId id;
WebPChunk chunk;
WebPMuxError err; WebPMuxError err;
ChunkInit(&chunk);
err = ChunkAssignData(&chunk, data, size, riff_size, copy_data); err = ChunkAssignData(&chunk, data, size, riff_size, copy_data);
if (err != WEBP_MUX_OK) goto Err; if (err != WEBP_MUX_OK) goto Err;
@ -164,12 +164,12 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
if (chunk_list == NULL) chunk_list = &mux->unknown_; if (chunk_list == NULL) chunk_list = &mux->unknown_;
if (ChunkSetNth(&chunk, chunk_list, 0) != WEBP_MUX_OK) goto Err; if (ChunkSetNth(&chunk, chunk_list, 0) != WEBP_MUX_OK) goto Err;
} }
{ {
const size_t data_size = ChunkDiskSize(&chunk); const size_t data_size = ChunkDiskSize(&chunk);
data += data_size; data += data_size;
size -= data_size; size -= data_size;
} }
ChunkInit(&chunk);
} }
// Validate mux if complete. // Validate mux if complete.
@ -179,6 +179,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
return mux; // All OK; return mux; // All OK;
Err: // Something bad happened. Err: // Something bad happened.
ChunkRelease(&chunk);
MuxImageDelete(wpi); MuxImageDelete(wpi);
WebPMuxDelete(mux); WebPMuxDelete(mux);
return NULL; return NULL;