summaryrefslogtreecommitdiff
path: root/libavcodec/snappy.c
diff options
context:
space:
mode:
authorTom Butterworth <bangnoise@gmail.com>2015-07-21 01:21:38 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-07-23 13:35:16 +0100
commit083cbc930d077651ea7e3fbc32ec45352cfed7e7 (patch)
tree80029690588869a1d9609d4c4ac6bd6ab880bcfe /libavcodec/snappy.c
parent7f388c0fabc51eca3106e7cc443393269435ab52 (diff)
snappy: Refactor so ff_snappy_uncompress() uses an existing buffer
Some uses of Snappy require uncompressing to positions within an existing buffer. Also adds a function to get the uncompressed length of Snappy data.
Diffstat (limited to 'libavcodec/snappy.c')
-rw-r--r--libavcodec/snappy.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/libavcodec/snappy.c b/libavcodec/snappy.c
index 13ef1ec137..df6c6b386a 100644
--- a/libavcodec/snappy.c
+++ b/libavcodec/snappy.c
@@ -128,7 +128,17 @@ static int64_t decode_len(GetByteContext *gb)
return len;
}
-int ff_snappy_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
+int64_t ff_snappy_peek_uncompressed_length(GetByteContext *gb)
+{
+ int pos = bytestream2_get_bytes_left(gb);
+ int64_t len = decode_len(gb);
+
+ bytestream2_seek(gb, -pos, SEEK_END);
+
+ return len;
+}
+
+int ff_snappy_uncompress(GetByteContext *gb, uint8_t *buf, int64_t *size)
{
int64_t len = decode_len(gb);
int ret = 0;
@@ -137,11 +147,11 @@ int ff_snappy_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
if (len < 0)
return len;
- if ((ret = av_reallocp(buf, len)) < 0)
- return AVERROR(ENOMEM);
+ if (len > *size)
+ return AVERROR_BUG;
*size = len;
- p = *buf;
+ p = buf;
while (bytestream2_get_bytes_left(gb) > 0) {
uint8_t s = bytestream2_get_byte(gb);
@@ -152,13 +162,13 @@ int ff_snappy_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
ret = snappy_literal(gb, p, len, val);
break;
case SNAPPY_COPY_1:
- ret = snappy_copy1(gb, *buf, p, len, val);
+ ret = snappy_copy1(gb, buf, p, len, val);
break;
case SNAPPY_COPY_2:
- ret = snappy_copy2(gb, *buf, p, len, val);
+ ret = snappy_copy2(gb, buf, p, len, val);
break;
case SNAPPY_COPY_4:
- ret = snappy_copy4(gb, *buf, p, len, val);
+ ret = snappy_copy4(gb, buf, p, len, val);
break;
}