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') ||

View File

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