Add NULL check in chunk APIs

Change-Id: I173ff6c9259111762580c1963ff60e34fd1e9b6b
This commit is contained in:
Urvang Joshi 2012-10-30 15:50:47 -07:00
parent a077072777
commit 02b4356875
3 changed files with 19 additions and 12 deletions

View File

@ -189,7 +189,7 @@ static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux, uint32_t tag) {
const WebPChunkId id = ChunkGetIdFromTag(tag); const WebPChunkId id = ChunkGetIdFromTag(tag);
WebPChunk** chunk_list; WebPChunk** chunk_list;
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT; assert(mux != NULL);
if (IsWPI(id)) return WEBP_MUX_INVALID_ARGUMENT; if (IsWPI(id)) return WEBP_MUX_INVALID_ARGUMENT;
chunk_list = MuxGetChunkListFromId(mux, id); chunk_list = MuxGetChunkListFromId(mux, id);
@ -199,6 +199,7 @@ static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux, uint32_t tag) {
} }
static WebPMuxError DeleteLoopCount(WebPMux* const mux) { static WebPMuxError DeleteLoopCount(WebPMux* const mux) {
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;
return MuxDeleteAllNamedData(mux, kChunks[IDX_LOOP].tag); return MuxDeleteAllNamedData(mux, kChunks[IDX_LOOP].tag);
} }
@ -207,13 +208,15 @@ static WebPMuxError DeleteLoopCount(WebPMux* const mux) {
WebPMuxError WebPMuxSetChunk(WebPMux* mux, const char fourcc[4], WebPMuxError WebPMuxSetChunk(WebPMux* mux, const char fourcc[4],
const WebPData* chunk_data, int copy_data) { const WebPData* chunk_data, int copy_data) {
const CHUNK_INDEX idx = ChunkGetIndexFromFourCC(fourcc); CHUNK_INDEX idx;
const uint32_t tag = ChunkGetTagFromFourCC(fourcc); uint32_t tag;
WebPMuxError err; WebPMuxError err;
if (mux == NULL || chunk_data == NULL || chunk_data->bytes == NULL || if (mux == NULL || fourcc == NULL || chunk_data == NULL ||
chunk_data->size > MAX_CHUNK_PAYLOAD) { chunk_data->bytes == NULL || chunk_data->size > MAX_CHUNK_PAYLOAD) {
return WEBP_MUX_INVALID_ARGUMENT; return WEBP_MUX_INVALID_ARGUMENT;
} }
idx = ChunkGetIndexFromFourCC(fourcc);
tag = ChunkGetTagFromFourCC(fourcc);
// Delete existing chunk(s) with the same 'fourcc'. // Delete existing chunk(s) with the same 'fourcc'.
err = MuxDeleteAllNamedData(mux, tag); err = MuxDeleteAllNamedData(mux, tag);
@ -377,6 +380,7 @@ WebPMuxError WebPMuxSetLoopCount(WebPMux* mux, int loop_count) {
// Delete API(s). // Delete API(s).
WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]) { WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]) {
if (mux == NULL || fourcc == NULL) return WEBP_MUX_INVALID_ARGUMENT;
return MuxDeleteAllNamedData(mux, ChunkGetTagFromFourCC(fourcc)); return MuxDeleteAllNamedData(mux, ChunkGetTagFromFourCC(fourcc));
} }

View File

@ -271,11 +271,14 @@ static WebPMuxError SynthesizeBitstream(const WebPMuxImage* const wpi,
WebPMuxError WebPMuxGetChunk(const WebPMux* mux, const char fourcc[4], WebPMuxError WebPMuxGetChunk(const WebPMux* mux, const char fourcc[4],
WebPData* chunk_data) { WebPData* chunk_data) {
const CHUNK_INDEX idx = ChunkGetIndexFromFourCC(fourcc); CHUNK_INDEX idx;
if (mux == NULL || chunk_data == NULL || IsWPI(kChunks[idx].id)) { if (mux == NULL || fourcc == NULL || chunk_data == NULL) {
return WEBP_MUX_INVALID_ARGUMENT; return WEBP_MUX_INVALID_ARGUMENT;
} }
if (idx != IDX_UNKNOWN) { // A known chunk type. idx = ChunkGetIndexFromFourCC(fourcc);
if (IsWPI(kChunks[idx].id)) { // An image chunk.
return WEBP_MUX_INVALID_ARGUMENT;
} else if (idx != IDX_UNKNOWN) { // A known chunk type.
return MuxGet(mux, idx, 1, chunk_data); return MuxGet(mux, idx, 1, chunk_data);
} else { // An unknown chunk type. } else { // An unknown chunk type.
const WebPChunk* const chunk = const WebPChunk* const chunk =

View File

@ -179,7 +179,7 @@ static WEBP_INLINE WebPMux* WebPMuxCreate(const WebPData* bitstream,
// copy_data - (in) value 1 indicates given data WILL be copied to the mux // copy_data - (in) value 1 indicates given data WILL be copied to the mux
// and value 0 indicates data will NOT be copied. // and value 0 indicates data will NOT be copied.
// Returns: // Returns:
// WEBP_MUX_INVALID_ARGUMENT - if mux or chunk_data is NULL // WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
// or if fourcc corresponds to an image chunk. // or if fourcc corresponds to an image chunk.
// WEBP_MUX_MEMORY_ERROR - on memory allocation error. // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
// WEBP_MUX_OK - on success. // WEBP_MUX_OK - on success.
@ -195,7 +195,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxSetChunk(
// e.g., "ICCP", "META" etc. // e.g., "ICCP", "META" etc.
// chunk_data - (out) returned chunk data // chunk_data - (out) returned chunk data
// Returns: // Returns:
// WEBP_MUX_INVALID_ARGUMENT - if either mux or chunk_data is NULL // WEBP_MUX_INVALID_ARGUMENT - if either mux, fourcc or chunk_data is NULL
// or if fourcc corresponds to an image chunk. // or if fourcc corresponds to an image chunk.
// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id. // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id.
// WEBP_MUX_OK - on success. // WEBP_MUX_OK - on success.
@ -208,7 +208,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetChunk(
// fourcc - (in) a character array containing the fourcc of the chunk; // fourcc - (in) a character array containing the fourcc of the chunk;
// e.g., "ICCP", "META" etc. // e.g., "ICCP", "META" etc.
// Returns: // Returns:
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL // WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL
// or if fourcc corresponds to an image chunk. // or if fourcc corresponds to an image chunk.
// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc. // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc.
// WEBP_MUX_OK - on success. // WEBP_MUX_OK - on success.