Commit 227c679c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

decomp: handle NULL reads (skipping data) properly - fixes #2409

parent 5c63462c
...@@ -143,6 +143,8 @@ static void *Thread (void *data) ...@@ -143,6 +143,8 @@ static void *Thread (void *data)
} }
static int Peek (stream_t *, const uint8_t **, unsigned int);
#define MIN_BLOCK (1 << 10) #define MIN_BLOCK (1 << 10)
#define MAX_BLOCK (1 << 20) #define MAX_BLOCK (1 << 20)
/** /**
...@@ -155,11 +157,17 @@ static int Read (stream_t *stream, void *buf, unsigned int buflen) ...@@ -155,11 +157,17 @@ static int Read (stream_t *stream, void *buf, unsigned int buflen)
block_t *peeked; block_t *peeked;
ssize_t length; ssize_t length;
if (buf == NULL) /* caller skips data, get big enough peek buffer */
buflen = Peek (stream, &(const uint8_t *){ NULL }, buflen);
if ((peeked = p_sys->peeked) != NULL) if ((peeked = p_sys->peeked) != NULL)
{ /* dequeue peeked data */ { /* dequeue peeked data */
length = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen; length = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen;
memcpy (buf, peeked->p_buffer, length); if (buf != NULL)
buf = ((char *)buf) + length; {
memcpy (buf, peeked->p_buffer, length);
buf = ((char *)buf) + length;
}
buflen -= length; buflen -= length;
peeked->p_buffer += length; peeked->p_buffer += length;
peeked->i_buffer -= length; peeked->i_buffer -= length;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment