aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2013-09-29 19:45:57 -0400
committerReinhard Tartler <siretart@tauware.de>2014-05-31 20:05:19 -0400
commitfa60904ebd58da33abf10b05e9933d24619cf096 (patch)
treec5925ddc0c3f55005d79812c89fbfa121a721fbd /libavcodec
parentb473fdcde329dfbe6d099247f65f51436a49e8c6 (diff)
downloadffmpeg-fa60904ebd58da33abf10b05e9933d24619cf096.tar.gz
bytestream: add bytestream2_copy_buffer() functions
This is basically an overread/overwrite-safe memcpy between a GetByteContext and a PutByteContext. CC:libav-stable@libav.org (cherry picked from commit 5748faf291fec297ef25d81962b52b3438f54278)
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/bytestream.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index 091cab8c8e..617724139a 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -333,6 +333,32 @@ static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
return p->eof;
}
+static av_always_inline unsigned int bytestream2_copy_bufferu(PutByteContext *p,
+ GetByteContext *g,
+ unsigned int size)
+{
+ memcpy(p->buffer, g->buffer, size);
+ p->buffer += size;
+ g->buffer += size;
+ return size;
+}
+
+static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p,
+ GetByteContext *g,
+ unsigned int size)
+{
+ int size2;
+
+ if (p->eof)
+ return 0;
+ size = FFMIN(g->buffer_end - g->buffer, size);
+ size2 = FFMIN(p->buffer_end - p->buffer, size);
+ if (size2 != size)
+ p->eof = 1;
+
+ return bytestream2_copy_bufferu(p, g, size2);
+}
+
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b,
uint8_t *dst,
unsigned int size)