Skip to content

Commit

Permalink
leb128: switch to uint64_t (#436)
Browse files Browse the repository at this point in the history
* leb128: switch to uint64_t

* set header size after check
  • Loading branch information
alfredh committed Jul 15, 2022
1 parent 19f7205 commit 3a3ee48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/re_av1.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct av1_obu_hdr {
size_t size; /**< Payload size */
};

int av1_leb128_encode(struct mbuf *mb, size_t value);
int av1_leb128_decode(struct mbuf *mb, size_t *value);
int av1_leb128_encode(struct mbuf *mb, uint64_t value);
int av1_leb128_decode(struct mbuf *mb, uint64_t *value);
int av1_obu_encode(struct mbuf *mb, uint8_t type, bool has_size,
size_t len, const uint8_t *payload);
int av1_obu_decode(struct av1_obu_hdr *hdr, struct mbuf *mb);
Expand Down
20 changes: 12 additions & 8 deletions src/av1/obu.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @return 0 if success, otherwise errorcode
*/
int av1_leb128_encode(struct mbuf *mb, size_t value)
int av1_leb128_encode(struct mbuf *mb, uint64_t value)
{
int err = 0;

Expand Down Expand Up @@ -56,9 +56,9 @@ int av1_leb128_encode(struct mbuf *mb, size_t value)
*
* @return 0 if success, otherwise errorcode
*/
int av1_leb128_decode(struct mbuf *mb, size_t *value)
int av1_leb128_decode(struct mbuf *mb, uint64_t *value)
{
size_t ret = 0;
uint64_t ret = 0;
unsigned i;

if (!mb || !value)
Expand All @@ -73,7 +73,7 @@ int av1_leb128_decode(struct mbuf *mb, size_t *value)

byte = mbuf_read_u8(mb);

ret |= (size_t)(byte & 0x7f) << (i * 7);
ret |= (uint64_t)(byte & 0x7f) << (i * 7);

if (!(byte & 0x80))
break;
Expand Down Expand Up @@ -169,16 +169,20 @@ int av1_obu_decode(struct av1_obu_hdr *hdr, struct mbuf *mb)
}

if (hdr->s) {
err = av1_leb128_decode(mb, &hdr->size);
uint64_t size;

err = av1_leb128_decode(mb, &size);
if (err)
return err;

if (hdr->size > mbuf_get_left(mb)) {
if (size > mbuf_get_left(mb)) {
DEBUG_WARNING("av1: obu decode: short packet:"
" %zu > %zu\n",
hdr->size, mbuf_get_left(mb));
" %llu > %zu\n",
size, mbuf_get_left(mb));
return EBADMSG;
}

hdr->size = (size_t)size;
}
else {
hdr->size = mbuf_get_left(mb);
Expand Down

0 comments on commit 3a3ee48

Please sign in to comment.