diff options
| author | Julian Andres Klode <jak@debian.org> | 2015-06-10 10:55:25 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2015-06-10 22:34:16 +0200 |
| commit | e7972b4ca116f6c1e40d83988c94c162d8b99821 (patch) | |
| tree | 062c0d8d437d87476cc3154955bae764dd744493 | |
| parent | 2e86ceae532feaa3a2297d57d8a578d553926f03 (diff) | |
| download | python-apt-e7972b4ca116f6c1e40d83988c94c162d8b99821.tar.gz | |
python/arfile.cc: Do not allow files larger than SIZE_MAX to be mapped
Also catch failed allocations, in case size is still too large.
This prepares for large file support, see Bug#742885
| -rw-r--r-- | python/arfile.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/python/arfile.cc b/python/arfile.cc index 3284ff7c..ac766f3d 100644 --- a/python/arfile.cc +++ b/python/arfile.cc @@ -179,10 +179,22 @@ static PyObject *ararchive_extractdata(PyArArchiveObject *self, PyObject *args) PyErr_Format(PyExc_LookupError,"No member named '%s'",name.path); return 0; } + if (member->Size > SIZE_MAX) { + PyErr_Format(PyExc_MemoryError, + "Member '%s' is too large to read into memory",name.path); + return 0; + } if (!self->Fd.Seek(member->Start)) return HandleErrors(); - char* value = new char[member->Size]; + char* value; + try { + value = new char[member->Size]; + } catch (std::bad_alloc&) { + PyErr_Format(PyExc_MemoryError, + "Member '%s' is too large to read into memory",name.path); + return 0; + } self->Fd.Read(value, member->Size, true); PyObject *result = PyBytes_FromStringAndSize(value, member->Size); delete[] value; |
