[FFmpeg-cvslog] bytestream: add bytestream2_copy_buffer() functions

Justin Ruggles git at videolan.org
Mon Apr 21 17:02:26 CEST 2014


ffmpeg | branch: release/1.1 | Justin Ruggles <justin.ruggles at gmail.com> | Sun Sep 29 19:45:57 2013 -0400| [d946e4c1bcfb6accd97f6d4cbfa324ef01913c8d] | committer: Sean McGovern

bytestream: add bytestream2_copy_buffer() functions

This is basically an overread/overwrite-safe memcpy between a
GetByteContext and a PutByteContext.

CC:libav-stable at libav.org
(cherry picked from commit 5748faf291fec297ef25d81962b52b3438f54278)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d946e4c1bcfb6accd97f6d4cbfa324ef01913c8d
---

 libavcodec/bytestream.h |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index 63d61f1..3eab225 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -325,6 +325,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)



More information about the ffmpeg-cvslog mailing list