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
file(0),
name(fileName),
readOnly(true),
- valid(true)
+ valid(true),
+ size(0)
{}
~FilePrivate()
const char *name;
bool readOnly;
bool valid;
+ ulong size;
static const uint bufferSize = 1024;
};
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);
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();
long endpos = tell();
seek(curpos, Beginning);
-
+
+ d->size = endpos;
return endpos;
}