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.
This commit is contained in:
Max Kellermann 2008-11-15 19:27:30 +01:00
parent c368a2f91c
commit acfba02310
2 changed files with 7 additions and 0 deletions

View File

@ -106,6 +106,9 @@ size_t decoder_read(struct decoder *decoder,
assert(is != NULL); assert(is != NULL);
assert(buffer != NULL); assert(buffer != NULL);
if (length == 0)
return 0;
while (true) { while (true) {
/* XXX don't allow decoder==NULL */ /* XXX don't allow decoder==NULL */
if (decoder != NULL && if (decoder != NULL &&

View File

@ -26,6 +26,7 @@
#endif #endif
#include <glib.h> #include <glib.h>
#include <assert.h>
static const struct input_plugin *const input_plugins[] = { static const struct input_plugin *const input_plugins[] = {
&input_plugin_file, &input_plugin_file,
@ -84,6 +85,9 @@ input_stream_seek(struct input_stream *is, off_t offset, int whence)
size_t size_t
input_stream_read(struct input_stream *is, void *ptr, size_t size) 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); return is->plugin->read(is, ptr, size);
} }