modplug: unknown size is -1; check for empty file

The input_stream API sets size to -1 when the size of the resource is
not known.  The modplug decoder checked for size==0, which would be an
empty file.
This commit is contained in:
Max Kellermann 2009-01-24 19:16:07 +01:00
parent 961d172200
commit 0c71640528

View File

@ -38,16 +38,23 @@ static GByteArray *mod_loadfile(struct decoder *decoder, struct input_stream *is
int total_len; int total_len;
int ret; int ret;
if (is->size == 0) {
g_warning("file is empty");
return NULL;
}
if (is->size > MODPLUG_FILE_LIMIT) {
g_warning("file too large");
return NULL;
}
//known/unknown size, preallocate array, lets read in chunks //known/unknown size, preallocate array, lets read in chunks
if (is->size) { if (is->size > 0) {
if (is->size > MODPLUG_FILE_LIMIT) {
g_warning("file too large\n");
return NULL;
}
bdatas = g_byte_array_sized_new(is->size); bdatas = g_byte_array_sized_new(is->size);
} else { } else {
bdatas = g_byte_array_sized_new(MODPLUG_PREALLOC_BLOCK); bdatas = g_byte_array_sized_new(MODPLUG_PREALLOC_BLOCK);
} }
data = g_malloc(MODPLUG_READ_BLOCK); data = g_malloc(MODPLUG_READ_BLOCK);
total_len = 0; total_len = 0;
do { do {