Use size_t for decode API input size parameters. Use a type more appropriate for buffer sizes that more cleanly integrates with I/O APIs. Removes some casting related to size_t use with C file I/O APIs (fread mainly). This changes the call signatures of aom_codec_decode() and aom_codec_peek_stream_info(), and updates the internal implementations. The single change to all API entries is and internal hooks is the change from "unsigned int" to size_t for the data_sz parameter. Change-Id: If293c537efa5c651184aac52efc001aba4ad187b
diff --git a/aom/aom_decoder.h b/aom/aom_decoder.h index 458e3bb..56eff00 100644 --- a/aom/aom_decoder.h +++ b/aom/aom_decoder.h
@@ -162,8 +162,7 @@ * buffer was too short. */ aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface, - const uint8_t *data, - unsigned int data_sz, + const uint8_t *data, size_t data_sz, aom_codec_stream_info_t *si); /*!\brief Return information about the current stream. @@ -212,7 +211,7 @@ * for recoverability capabilities. */ aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, - unsigned int data_sz, void *user_priv); + size_t data_sz, void *user_priv); /*!\brief Decoded frames iterator *
diff --git a/aom/internal/aom_codec_internal.h b/aom/internal/aom_codec_internal.h index a633d4c..bff5a86 100644 --- a/aom/internal/aom_codec_internal.h +++ b/aom/internal/aom_codec_internal.h
@@ -113,7 +113,7 @@ * Bitstream is parsable and stream information updated */ typedef aom_codec_err_t (*aom_codec_peek_si_fn_t)(const uint8_t *data, - unsigned int data_sz, + size_t data_sz, aom_codec_stream_info_t *si); /*!\brief Return information about the current stream. @@ -195,7 +195,7 @@ */ typedef aom_codec_err_t (*aom_codec_decode_fn_t)(aom_codec_alg_priv_t *ctx, const uint8_t *data, - unsigned int data_sz, + size_t data_sz, void *user_priv); /*!\brief Decoded frames iterator
diff --git a/aom/src/aom_decoder.c b/aom/src/aom_decoder.c index ecbf838..e0cec10 100644 --- a/aom/src/aom_decoder.c +++ b/aom/src/aom_decoder.c
@@ -61,8 +61,7 @@ } aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface, - const uint8_t *data, - unsigned int data_sz, + const uint8_t *data, size_t data_sz, aom_codec_stream_info_t *si) { aom_codec_err_t res; @@ -99,7 +98,7 @@ } aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, - unsigned int data_sz, void *user_priv) { + size_t data_sz, void *user_priv) { aom_codec_err_t res; /* Sanity checks */
diff --git a/aomdec.c b/aomdec.c index 361e211..ddfc3a5 100644 --- a/aomdec.c +++ b/aomdec.c
@@ -797,8 +797,7 @@ aom_usec_timer_start(&timer); - if (aom_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, - NULL)) { + if (aom_codec_decode(&decoder, buf, bytes_in_buffer, NULL)) { const char *detail = aom_codec_error_detail(&decoder); warn("Failed to decode frame %d: %s", frame_in, aom_codec_error(&decoder));
diff --git a/av1/av1_dx_iface.c b/av1/av1_dx_iface.c index d514535..a3e2f2b 100644 --- a/av1/av1_dx_iface.c +++ b/av1/av1_dx_iface.c
@@ -204,7 +204,7 @@ } static aom_codec_err_t decoder_peek_si_internal(const uint8_t *data, - unsigned int data_sz, + size_t data_sz, aom_codec_stream_info_t *si, int *is_intra_only) { int intra_only_flag = 0; @@ -275,8 +275,7 @@ return AOM_CODEC_OK; } -static aom_codec_err_t decoder_peek_si(const uint8_t *data, - unsigned int data_sz, +static aom_codec_err_t decoder_peek_si(const uint8_t *data, size_t data_sz, aom_codec_stream_info_t *si) { return decoder_peek_si_internal(data, data_sz, si, NULL); } @@ -459,7 +458,7 @@ } static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx, - const uint8_t **data, uint64_t data_sz, + const uint8_t **data, size_t data_sz, void *user_priv) { const AVxWorkerInterface *const winterface = aom_get_worker_interface(); @@ -469,8 +468,8 @@ if (!ctx->si.h) { int is_intra_only = 0; ctx->si.is_annexb = ctx->is_annexb; - const aom_codec_err_t res = decoder_peek_si_internal( - *data, (unsigned int)data_sz, &ctx->si, &is_intra_only); + const aom_codec_err_t res = + decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only); if (res != AOM_CODEC_OK) return res; if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR; @@ -509,7 +508,7 @@ } static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx, - const uint8_t *data, unsigned int data_sz, + const uint8_t *data, size_t data_sz, void *user_priv) { const uint8_t *data_start = data; const uint8_t *const data_end = data + data_sz; @@ -555,7 +554,9 @@ frame_size = (uint64_t)(data_end - data_start); } - res = decode_one(ctx, &data_start, frame_size, user_priv); + if (frame_size > UINT32_MAX) return AOM_CODEC_CORRUPT_FRAME; + + res = decode_one(ctx, &data_start, (size_t)frame_size, user_priv); if (res != AOM_CODEC_OK) return res; // Allow extra zero bytes after the frame end
diff --git a/examples/decode_to_md5.c b/examples/decode_to_md5.c index 75bb97d..0e108e2 100644 --- a/examples/decode_to_md5.c +++ b/examples/decode_to_md5.c
@@ -110,7 +110,7 @@ size_t frame_size = 0; const unsigned char *frame = aom_video_reader_get_frame(reader, &frame_size); - if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, NULL)) + if (aom_codec_decode(&codec, frame, frame_size, NULL)) die_codec(&codec, "Failed to decode frame"); while ((img = aom_codec_get_frame(&codec, &iter)) != NULL) {
diff --git a/examples/decode_with_drops.c b/examples/decode_with_drops.c index 362f9ad..bd32c87 100644 --- a/examples/decode_with_drops.c +++ b/examples/decode_with_drops.c
@@ -123,7 +123,7 @@ if (!skip) { putc('.', stdout); - if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, NULL)) + if (aom_codec_decode(&codec, frame, frame_size, NULL)) die_codec(&codec, "Failed to decode frame."); while ((img = aom_codec_get_frame(&codec, &iter)) != NULL)
diff --git a/examples/lightfield_decoder.c b/examples/lightfield_decoder.c index b1a3921..0b52487 100644 --- a/examples/lightfield_decoder.c +++ b/examples/lightfield_decoder.c
@@ -137,7 +137,7 @@ size_t frame_size = 0; const unsigned char *frame = aom_video_reader_get_frame(reader, &frame_size); - if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, NULL)) + if (aom_codec_decode(&codec, frame, frame_size, NULL)) die_codec(&codec, "Failed to decode frame."); while ((img = aom_codec_get_frame(&codec, &iter)) != NULL) {
diff --git a/examples/scalable_decoder.c b/examples/scalable_decoder.c index 837f07a..37cf299 100644 --- a/examples/scalable_decoder.c +++ b/examples/scalable_decoder.c
@@ -149,7 +149,7 @@ &buffer_size)) { aom_codec_iter_t iter = NULL; aom_image_t *img = NULL; - if (aom_codec_decode(&codec, buf, (unsigned int)bytes_in_buffer, NULL)) + if (aom_codec_decode(&codec, buf, bytes_in_buffer, NULL)) die_codec(&codec, "Failed to decode frame."); while ((img = aom_codec_get_frame(&codec, &iter)) != NULL) {
diff --git a/examples/simple_decoder.c b/examples/simple_decoder.c index e7c6a7d..a784f18 100644 --- a/examples/simple_decoder.c +++ b/examples/simple_decoder.c
@@ -125,7 +125,7 @@ size_t frame_size = 0; const unsigned char *frame = aom_video_reader_get_frame(reader, &frame_size); - if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, NULL)) + if (aom_codec_decode(&codec, frame, frame_size, NULL)) die_codec(&codec, "Failed to decode frame."); while ((img = aom_codec_get_frame(&codec, &iter)) != NULL) {
diff --git a/test/decode_test_driver.cc b/test/decode_test_driver.cc index 089cc9b..99a9e8d 100644 --- a/test/decode_test_driver.cc +++ b/test/decode_test_driver.cc
@@ -22,8 +22,8 @@ aom_codec_err_t Decoder::PeekStream(const uint8_t *cxdata, size_t size, aom_codec_stream_info_t *stream_info) { - return aom_codec_peek_stream_info( - CodecInterface(), cxdata, static_cast<unsigned int>(size), stream_info); + return aom_codec_peek_stream_info(CodecInterface(), cxdata, size, + stream_info); } aom_codec_err_t Decoder::DecodeFrame(const uint8_t *cxdata, size_t size) { @@ -35,8 +35,7 @@ aom_codec_err_t res_dec; InitOnce(); API_REGISTER_STATE_CHECK( - res_dec = aom_codec_decode(&decoder_, cxdata, - static_cast<unsigned int>(size), user_priv)); + res_dec = aom_codec_decode(&decoder_, cxdata, size, user_priv)); return res_dec; }