mirror of
https://github.com/taglib/taglib.git
synced 2025-07-18 13:04:18 -04:00
Make sure that buffer allocations for file reads aren't completely bogus.
Specifically make sure that we don't actually allocate a buffer for a read that extends beyond the end of the file. BUG:101401 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@438035 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
@ -36,7 +36,8 @@ public:
|
||||
file(0),
|
||||
name(fileName),
|
||||
readOnly(true),
|
||||
valid(true)
|
||||
valid(true),
|
||||
size(0)
|
||||
{}
|
||||
|
||||
~FilePrivate()
|
||||
@ -48,6 +49,7 @@ public:
|
||||
const char *name;
|
||||
bool readOnly;
|
||||
bool valid;
|
||||
ulong size;
|
||||
static const uint bufferSize = 1024;
|
||||
};
|
||||
|
||||
@ -85,6 +87,12 @@ ByteVector File::readBlock(ulong length)
|
||||
return ByteVector::null;
|
||||
}
|
||||
|
||||
if(length > FilePrivate::bufferSize &&
|
||||
length > ulong(File::length()))
|
||||
{
|
||||
length = File::length();
|
||||
}
|
||||
|
||||
ByteVector v(static_cast<uint>(length));
|
||||
const int count = fread(v.data(), sizeof(char), length, d->file);
|
||||
v.resize(count);
|
||||
@ -446,8 +454,13 @@ long File::tell() const
|
||||
|
||||
long File::length()
|
||||
{
|
||||
// Do some caching in case we do multiple calls.
|
||||
|
||||
if(d->size > 0)
|
||||
return d->size;
|
||||
|
||||
if(!d->file)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
long curpos = tell();
|
||||
|
||||
@ -455,7 +468,8 @@ long File::length()
|
||||
long endpos = tell();
|
||||
|
||||
seek(curpos, Beginning);
|
||||
|
||||
|
||||
d->size = endpos;
|
||||
return endpos;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user