summaryrefslogtreecommitdiff
path: root/python/tarfile.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2010-01-24 17:56:30 +0100
committerJulian Andres Klode <jak@debian.org>2010-01-24 17:56:30 +0100
commit3836c5cfae107ea242c22d8dfbc42322cbe08186 (patch)
treefbc85ce51c4c34af28155952cac4377d65e7e274 /python/tarfile.cc
parent1e2f8799f0b6fb2da2770150749b4dd6a208e494 (diff)
downloadpython-apt-3836c5cfae107ea242c22d8dfbc42322cbe08186.tar.gz
* python/tarfile.cc:
- When extracting, only allocate a new buffer if the old one was too small. - Do not segfault if TarFile.go() is called without a member name.
Diffstat (limited to 'python/tarfile.cc')
-rw-r--r--python/tarfile.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/python/tarfile.cc b/python/tarfile.cc
index 9c3797fb..c1e5f48d 100644
--- a/python/tarfile.cc
+++ b/python/tarfile.cc
@@ -49,6 +49,8 @@ public:
bool error;
// Place where the copy of the data is stored.
char *copy;
+ // The size of the copy
+ size_t copy_size;
virtual bool DoItem(Item &Itm,int &Fd);
virtual bool FinishedFile(Item &Itm,int Fd);
@@ -72,8 +74,12 @@ public:
bool PyDirStream::DoItem(Item &Itm, int &Fd)
{
if (!member || strcmp(Itm.Name, member) == 0) {
- delete[] copy;
- copy = new char[Itm.Size];
+ // Allocate a new buffer if the old one is too small.
+ if (copy == NULL || copy_size < Itm.Size) {
+ delete[] copy;
+ copy = new char[Itm.Size];
+ copy_size = Itm.Size;
+ }
Fd = -2;
}
return true;
@@ -91,7 +97,7 @@ bool PyDirStream::FinishedFile(Item &Itm,int Fd)
if (member && strcmp(Itm.Name, member) != 0)
// Skip non-matching Items, if a specific one is requested.
return true;
-
+
// Clear the old objects and create new ones.
Py_XDECREF(py_member);
Py_XDECREF(py_data);
@@ -366,7 +372,7 @@ static PyObject *tarfile_go(PyObject *self, PyObject *args)
char *member = 0;
if (PyArg_ParseTuple(args,"O|s",&callback,&member) == 0)
return 0;
- if (strcmp(member, "") == 0)
+ if (member && strcmp(member, "") == 0)
member = 0;
pkgDirStream Extract;
PyDirStream stream(callback, member);