[vlc-commits] image: fix loading unsized streams (fixes #17141)

Rémi Denis-Courmont git at videolan.org
Wed Jul 6 21:32:39 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jul  6 22:32:07 2016 +0300| [9af197386df8efa6a4948170def432180f3ff40d] | committer: Rémi Denis-Courmont

image: fix loading unsized streams (fixes #17141)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9af197386df8efa6a4948170def432180f3ff40d
---

 modules/demux/image.c |   29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/modules/demux/image.c b/modules/demux/image.c
index 43c4847..9a5f104 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -111,17 +111,30 @@ struct demux_sys_t
 
 static block_t *Load(demux_t *demux)
 {
-    const int     max_size = 4096 * 4096 * 8;
-    const int64_t size = stream_Size(demux->s);
-    if (size < 0 || size > max_size) {
-        msg_Err(demux, "Rejecting image based on its size (%"PRId64" > %d)", size, max_size);
+    const unsigned max_size = 4096 * 4096 * 8;
+    uint64_t size;
+
+    if (stream_GetSize(demux->s, &size) == VLC_SUCCESS) {
+        if (size > max_size) {
+            msg_Err(demux, "image too large (%"PRIu64" > %u), rejected",
+                    size, max_size);
+            return NULL;
+        }
+    } else
+        size = max_size;
+
+    block_t *block = block_Alloc(size);
+    if (block == NULL)
+        return NULL;
+
+    ssize_t val = stream_Read(demux->s, block->p_buffer, size);
+    if (val < 0) {
+        block_Release(block);
         return NULL;
     }
 
-    if (size > 0)
-        return stream_Block(demux->s, size);
-    /* TODO */
-    return NULL;
+    block->i_buffer = val;
+    return block;
 }
 
 static block_t *Decode(demux_t *demux,



More information about the vlc-commits mailing list