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; mux->state_ = WEBP_MUX_STATE_PARTIAL;
} }
WebPMux* WebPMuxNew(void) { WebPMux* WebPNewInternal(int version) {
WebPMux* const mux = (WebPMux*)malloc(sizeof(WebPMux)); WebPMux* const mux = (version == WEBP_MUX_ABI_VERSION) ?
(WebPMux*)malloc(sizeof(WebPMux)) : NULL;
if (mux) MuxInit(mux); if (mux) MuxInit(mux);
return 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. // Create a mux object from WebP-RIFF data.
WebPMux* WebPMuxCreate(const uint8_t* data, size_t size, int copy_data, WebPMux* WebPMuxCreateInternal(const uint8_t* data, size_t size, int copy_data,
WebPMuxState* const mux_state) { WebPMuxState* const mux_state, int version) {
size_t riff_size; size_t riff_size;
uint32_t tag; uint32_t tag;
const uint8_t* end; 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; if (mux_state) *mux_state = WEBP_MUX_STATE_PARTIAL;
// Sanity checks. // Sanity checks.
if (version != WEBP_MUX_ABI_VERSION) goto Err; // version mismatch
if (data == NULL) goto Err; if (data == NULL) goto Err;
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') ||

View File

@ -51,6 +51,8 @@
extern "C" { extern "C" {
#endif #endif
#define WEBP_MUX_ABI_VERSION 0x0000
// Error codes // Error codes
typedef enum { typedef enum {
WEBP_MUX_OK = 1, WEBP_MUX_OK = 1,
@ -90,10 +92,15 @@ typedef struct {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Life of a Mux object // Life of a Mux object
// Internal, version-checked, entry point
WEBP_EXTERN(WebPMux*) WebPNewInternal(int);
// Creates an empty mux object. // Creates an empty mux object.
// Returns: // Returns:
// A pointer to the newly created empty mux object. // A pointer to the newly created empty mux object.
WEBP_EXTERN(WebPMux*) WebPMuxNew(void); static WEBP_INLINE WebPMux* WebPMuxNew(void) {
return WebPNewInternal(WEBP_MUX_ABI_VERSION);
}
// Deletes the mux object. // Deletes the mux object.
// Parameters: // Parameters:
@ -103,6 +110,10 @@ WEBP_EXTERN(void) WebPMuxDelete(WebPMux* const mux);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Mux creation. // Mux creation.
// Internal, version-checked, entry point
WEBP_EXTERN(WebPMux*) WebPMuxCreateInternal(const uint8_t*, size_t,
int, WebPMuxState* const, int);
// Creates a mux object from raw data given in WebP RIFF format. // Creates a mux object from raw data given in WebP RIFF format.
// Parameters: // Parameters:
// data - (in) the raw data in WebP RIFF format // data - (in) the raw data in WebP RIFF format
@ -114,9 +125,12 @@ WEBP_EXTERN(void) WebPMuxDelete(WebPMux* const mux);
// Returns: // Returns:
// A pointer to the mux object created from given data - on success. // A pointer to the mux object created from given data - on success.
// NULL - In case of invalid data or memory error. // NULL - In case of invalid data or memory error.
WEBP_EXTERN(WebPMux*) WebPMuxCreate(const uint8_t* data, size_t size, static WEBP_INLINE WebPMux* WebPMuxCreate(const uint8_t* data, size_t size,
int copy_data, int copy_data,
WebPMuxState* const mux_state); WebPMuxState* const mux_state) {
return WebPMuxCreateInternal(
data, size, copy_data, mux_state, WEBP_MUX_ABI_VERSION);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Single Image. // Single Image.