mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Improve robustness of seek() by adding some sanity checks.
This commit is contained in:
parent
8f5e89c900
commit
022ba32c1a
12
src/file.cpp
12
src/file.cpp
|
@ -168,8 +168,10 @@ void FileBase::write(const void *buf, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
off_t FileBase::seek(off_t off, int whence)
|
off_t FileBase::seek(upx_int64_t off64, int whence)
|
||||||
{
|
{
|
||||||
|
(void) mem_size(1, off64 >= 0 ? off64 : -off64); // sanity check
|
||||||
|
off_t off = ACC_ICONV(off_t, off64);
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
throwIOException("bad seek 1");
|
throwIOException("bad seek 1");
|
||||||
if (whence == SEEK_SET) {
|
if (whence == SEEK_SET) {
|
||||||
|
@ -285,9 +287,9 @@ int InputFile::readx(MemBuffer &buf, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
off_t InputFile::seek(off_t off, int whence)
|
off_t InputFile::seek(upx_int64_t off64, int whence)
|
||||||
{
|
{
|
||||||
off_t pos = super::seek(off,whence);
|
off_t pos = super::seek(off64, whence);
|
||||||
if (_length < pos)
|
if (_length < pos)
|
||||||
throwIOException("bad seek 4");
|
throwIOException("bad seek 4");
|
||||||
return pos;
|
return pos;
|
||||||
|
@ -402,8 +404,10 @@ void OutputFile::rewrite(const void *buf, int len)
|
||||||
bytes_written -= len; // restore
|
bytes_written -= len; // restore
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t OutputFile::seek(off_t off, int whence)
|
off_t OutputFile::seek(upx_int64_t off64, int whence)
|
||||||
{
|
{
|
||||||
|
(void) mem_size(1, off64 >= 0 ? off64 : -off64); // sanity check
|
||||||
|
off_t off = ACC_ICONV(off_t, off64);
|
||||||
assert(!opt->to_stdout);
|
assert(!opt->to_stdout);
|
||||||
switch (whence) {
|
switch (whence) {
|
||||||
case SEEK_SET: {
|
case SEEK_SET: {
|
||||||
|
|
|
@ -67,7 +67,7 @@ protected:
|
||||||
virtual int read(void *buf, int len);
|
virtual int read(void *buf, int len);
|
||||||
virtual int readx(void *buf, int len);
|
virtual int readx(void *buf, int len);
|
||||||
virtual void write(const void *buf, int len);
|
virtual void write(const void *buf, int len);
|
||||||
virtual off_t seek(off_t off, int whence);
|
virtual off_t seek(upx_int64_t off, int whence);
|
||||||
virtual off_t tell() const;
|
virtual off_t tell() const;
|
||||||
|
|
||||||
int _fd;
|
int _fd;
|
||||||
|
@ -106,7 +106,7 @@ public:
|
||||||
virtual int read(MemBuffer &buf, int len);
|
virtual int read(MemBuffer &buf, int len);
|
||||||
virtual int readx(MemBuffer &buf, int len);
|
virtual int readx(MemBuffer &buf, int len);
|
||||||
|
|
||||||
virtual off_t seek(off_t off, int whence);
|
virtual off_t seek(upx_int64_t off, int whence);
|
||||||
virtual off_t tell() const;
|
virtual off_t tell() const;
|
||||||
virtual off_t st_size_orig() const;
|
virtual off_t st_size_orig() const;
|
||||||
protected:
|
protected:
|
||||||
|
@ -142,7 +142,7 @@ public:
|
||||||
virtual off_t st_size() const; // { return _length; }
|
virtual off_t st_size() const; // { return _length; }
|
||||||
|
|
||||||
// FIXME - these won't work when using the '--stdout' option
|
// FIXME - these won't work when using the '--stdout' option
|
||||||
virtual off_t seek(off_t off, int whence);
|
virtual off_t seek(upx_int64_t off, int whence);
|
||||||
virtual void rewrite(const void *buf, int len);
|
virtual void rewrite(const void *buf, int len);
|
||||||
|
|
||||||
// util
|
// util
|
||||||
|
|
Loading…
Reference in New Issue
Block a user