Merge "Add NULL check in chunk APIs"

This commit is contained in:
pascal massimino 2012-10-31 16:07:24 -07:00 committed by Gerrit Code Review
commit a61a824b3a
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);
WebPChunk** chunk_list;
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;
assert(mux != NULL);
if (IsWPI(id)) return WEBP_MUX_INVALID_ARGUMENT;
chunk_list = MuxGetChunkListFromId(mux, id);
@ -199,6 +199,7 @@ static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux, uint32_t tag) {
}
static WebPMuxError DeleteLoopCount(WebPMux* const mux) {
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;
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],
const WebPData* chunk_data, int copy_data) {
const CHUNK_INDEX idx = ChunkGetIndexFromFourCC(fourcc);
const uint32_t tag = ChunkGetTagFromFourCC(fourcc);
CHUNK_INDEX idx;
uint32_t tag;
WebPMuxError err;
if (mux == NULL || chunk_data == NULL || chunk_data->bytes == NULL ||
chunk_data->size > MAX_CHUNK_PAYLOAD) {
if (mux == NULL || fourcc == NULL || chunk_data == NULL ||
chunk_data->bytes == NULL || chunk_data->size > MAX_CHUNK_PAYLOAD) {
return WEBP_MUX_INVALID_ARGUMENT;
}
idx = ChunkGetIndexFromFourCC(fourcc);
tag = ChunkGetTagFromFourCC(fourcc);
// Delete existing chunk(s) with the same 'fourcc'.
err = MuxDeleteAllNamedData(mux, tag);
@ -377,6 +380,7 @@ WebPMuxError WebPMuxSetLoopCount(WebPMux* mux, int loop_count) {
// Delete API(s).
WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]) {
if (mux == NULL || fourcc == NULL) return WEBP_MUX_INVALID_ARGUMENT;
return MuxDeleteAllNamedData(mux, ChunkGetTagFromFourCC(fourcc));
}

View File

@ -271,13 +271,16 @@ static WebPMuxError SynthesizeBitstream(const WebPMuxImage* const wpi,
WebPMuxError WebPMuxGetChunk(const WebPMux* mux, const char fourcc[4],
WebPData* chunk_data) {
const CHUNK_INDEX idx = ChunkGetIndexFromFourCC(fourcc);
if (mux == NULL || chunk_data == NULL || IsWPI(kChunks[idx].id)) {
CHUNK_INDEX idx;
if (mux == NULL || fourcc == NULL || chunk_data == NULL) {
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);
} else { // An unknown chunk type.
} else { // An unknown chunk type.
const WebPChunk* const chunk =
ChunkSearchList(mux->unknown_, 1, ChunkGetTagFromFourCC(fourcc));
if (chunk == NULL) return WEBP_MUX_NOT_FOUND;

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
// and value 0 indicates data will NOT be copied.
// 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.
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
// WEBP_MUX_OK - on success.
@ -195,7 +195,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxSetChunk(
// e.g., "ICCP", "META" etc.
// chunk_data - (out) returned chunk data
// 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.
// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id.
// WEBP_MUX_OK - on success.
@ -208,7 +208,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetChunk(
// fourcc - (in) a character array containing the fourcc of the chunk;
// e.g., "ICCP", "META" etc.
// 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.
// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc.
// WEBP_MUX_OK - on success.