From acfba02310a1b8159440dd71bdf7c7fefb7ef8fb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 15 Nov 2008 19:27:30 +0100 Subject: decoder: check length==0 in decoder_read() When the caller passes length==0, decoder_read() entered an endless loop. Check that condition before entering the "while" loop. --- src/decoder_api.c | 3 +++ src/input_stream.c | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/decoder_api.c b/src/decoder_api.c index 08e6b1956..0aca4da95 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -106,6 +106,9 @@ size_t decoder_read(struct decoder *decoder, assert(is != NULL); assert(buffer != NULL); + if (length == 0) + return 0; + while (true) { /* XXX don't allow decoder==NULL */ if (decoder != NULL && diff --git a/src/input_stream.c b/src/input_stream.c index 86c0b9246..be547912e 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -26,6 +26,7 @@ #endif #include +#include static const struct input_plugin *const input_plugins[] = { &input_plugin_file, @@ -84,6 +85,9 @@ input_stream_seek(struct input_stream *is, off_t offset, int whence) size_t input_stream_read(struct input_stream *is, void *ptr, size_t size) { + assert(ptr != NULL); + assert(size > 0); + return is->plugin->read(is, ptr, size); } -- cgit v1.2.3