diff options
author | Max Kellermann <max@duempel.org> | 2014-08-19 20:53:02 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-08-19 20:53:02 +0200 |
commit | 2e64afca27e608e7f9e3be38cb6afd14211933ef (patch) | |
tree | 00e8d8479c2fa53508d0eef8f4e6f4110befb14b /src/decoder/plugins | |
parent | 51cda0be2a82a4557b7c5944f268edc28745fae8 (diff) | |
download | mpd-2e64afca27e608e7f9e3be38cb6afd14211933ef.tar.gz mpd-2e64afca27e608e7f9e3be38cb6afd14211933ef.tar.xz mpd-2e64afca27e608e7f9e3be38cb6afd14211933ef.zip |
decoder/modplug: check InputStream::KnownSize()
Diffstat (limited to '')
-rw-r--r-- | src/decoder/plugins/ModplugDecoderPlugin.cxx | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/decoder/plugins/ModplugDecoderPlugin.cxx b/src/decoder/plugins/ModplugDecoderPlugin.cxx index 336870817..e76737345 100644 --- a/src/decoder/plugins/ModplugDecoderPlugin.cxx +++ b/src/decoder/plugins/ModplugDecoderPlugin.cxx @@ -54,24 +54,29 @@ modplug_decoder_init(const config_param ¶m) static WritableBuffer<uint8_t> mod_loadfile(Decoder *decoder, InputStream &is) { - const InputStream::offset_type size = is.GetSize(); + //known/unknown size, preallocate array, lets read in chunks - if (size == 0) { - LogWarning(modplug_domain, "file is empty"); - return { nullptr, 0 }; - } + const bool is_stream = !is.KnownSize(); - if (size > MODPLUG_FILE_LIMIT) { - LogWarning(modplug_domain, "file too large"); - return { nullptr, 0 }; - } + WritableBuffer<uint8_t> buffer; + if (is_stream) + buffer.size = MODPLUG_PREALLOC_BLOCK; + else { + const auto size = is.GetSize(); + + if (size == 0) { + LogWarning(modplug_domain, "file is empty"); + return { nullptr, 0 }; + } - //known/unknown size, preallocate array, lets read in chunks + if (size > MODPLUG_FILE_LIMIT) { + LogWarning(modplug_domain, "file too large"); + return { nullptr, 0 }; + } - const bool is_stream = size < 0; + buffer.size = size; + } - WritableBuffer<uint8_t> buffer; - buffer.size = is_stream ? MODPLUG_PREALLOC_BLOCK : size; buffer.data = new uint8_t[buffer.size]; uint8_t *const end = buffer.end(); |