mux: add version checked entry points

Change-Id: I3bf5b25b17c06ec092f8ad1c14eea411aa9471c1
This commit is contained in:
James Zern
2012-04-25 17:27:16 -07:00
parent 6a0abdaa3a
commit 03f1f49321
3 changed files with 24 additions and 8 deletions

View File

@ -26,8 +26,9 @@ static void MuxInit(WebPMux* const mux) {
mux->state_ = WEBP_MUX_STATE_PARTIAL;
}
WebPMux* WebPMuxNew(void) {
WebPMux* const mux = (WebPMux*)malloc(sizeof(WebPMux));
WebPMux* WebPNewInternal(int version) {
WebPMux* const mux = (version == WEBP_MUX_ABI_VERSION) ?
(WebPMux*)malloc(sizeof(WebPMux)) : NULL;
if (mux) MuxInit(mux);
return mux;
}

View File

@ -74,8 +74,8 @@ static WebPMuxError ChunkAssignData(WebPChunk* chunk, const uint8_t* data,
//------------------------------------------------------------------------------
// Create a mux object from WebP-RIFF data.
WebPMux* WebPMuxCreate(const uint8_t* data, size_t size, int copy_data,
WebPMuxState* const mux_state) {
WebPMux* WebPMuxCreateInternal(const uint8_t* data, size_t size, int copy_data,
WebPMuxState* const mux_state, int version) {
size_t riff_size;
uint32_t tag;
const uint8_t* end;
@ -85,6 +85,7 @@ WebPMux* WebPMuxCreate(const uint8_t* data, size_t size, int copy_data,
if (mux_state) *mux_state = WEBP_MUX_STATE_PARTIAL;
// Sanity checks.
if (version != WEBP_MUX_ABI_VERSION) goto Err; // version mismatch
if (data == NULL) goto Err;
if (size < RIFF_HEADER_SIZE) return NULL;
if (GetLE32(data + 0) != mktag('R', 'I', 'F', 'F') ||