From e1c3b6b4d481998a8656952bcc3f6bbacd681515 Mon Sep 17 00:00:00 2001 From: James Hunt Date: Mon, 1 Oct 2012 09:10:49 +0100 Subject: python/cache.cc: PkgCacheGetIsMultiArch(): Return calculated value rather than a random one. --- python/cache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/cache.cc b/python/cache.cc index c51bd4af..10561ca0 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -286,7 +286,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { static PyObject *PkgCacheGetIsMultiArch(PyObject *Self, void*) { pkgCache *Cache = GetCpp(Self); - PyBool_FromLong(Cache->MultiArchCache()); + return PyBool_FromLong(Cache->MultiArchCache()); } static PyGetSetDef PkgCacheGetSet[] = { -- cgit v1.2.3 From 8d1fae9e2bb03225c81ac1f0719408618d86eb52 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 2 Oct 2012 11:32:15 +0200 Subject: merge patch from Barry to fix #1030278 --- debian/changelog | 8 ++++++++ python/string.cc | 28 ++++++++++++++++++++-------- tests/test_lp1030278.py | 22 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 tests/test_lp1030278.py (limited to 'python') diff --git a/debian/changelog b/debian/changelog index 66da3ea0..894502e2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,6 +14,14 @@ python-apt (0.8.8) UNRELEASED; urgency=low check the keys fingerprint before importing. This avoids man-in-the-middle attacks (LP: #1016643) + [ Barry Warsaw ] + * python/string.cc, tests/test_lp1030278.py: Fix StrSizeToStr() so that + 1) it first checks for PyLong-ness so that in Python 3 on i386, it + will be able to convert larger numbers (via doubles rather than ints); + 2) before doing the conversions through the apt API, check to see if a + Python exception occurred, e.g. OverflowError, and return an error + condition in that case instead of masking it. (LP: #1030278) + [ James Hunt ] * python/cache.cc: PkgCacheGetIsMultiArch(): Return calculated value rather than a random one. diff --git a/python/string.cc b/python/string.cc index 7abe2d17..62aa34e7 100644 --- a/python/string.cc +++ b/python/string.cc @@ -64,17 +64,29 @@ MkInt(StrTimeRFC1123,TimeRFC1123, long long, "L"); PyObject *StrSizeToStr(PyObject *Self,PyObject *Args) { PyObject *Obj; + double value; + if (PyArg_ParseTuple(Args,"O",&Obj) == 0) return 0; - if (PyInt_Check(Obj)) - return CppPyString(SizeToStr(PyInt_AsLong(Obj))); + // In Python 3, PyInt_Check is aliased to PyLong_Check and PyInt_AsLong is + // aliased to PyLong_AsLong. Therefore we do the actual long checks first + // so that if it is a long in Python 3, the value will be converted to a + // double rather than a long. This avoids OverflowError regressions in + // Python 3. LP: #1030278 if (PyLong_Check(Obj)) - return CppPyString(SizeToStr(PyLong_AsDouble(Obj))); - if (PyFloat_Check(Obj)) - return CppPyString(SizeToStr(PyFloat_AsDouble(Obj))); - - PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); - return 0; + value = PyLong_AsDouble(Obj); + else if (PyInt_Check(Obj)) + value = PyInt_AsLong(Obj); + else if (PyFloat_Check(Obj)) + value = PyFloat_AsDouble(Obj); + else { + PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); + return 0; + } + // Check for OverflowErrors or other exceptions during conversion. + if (PyErr_Occurred()) + return 0; + return CppPyString(SizeToStr(value)); } PyObject *StrQuoteString(PyObject *Self,PyObject *Args) diff --git a/tests/test_lp1030278.py b/tests/test_lp1030278.py new file mode 100644 index 00000000..1cbc2c18 --- /dev/null +++ b/tests/test_lp1030278.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Regression test for LP: #1030278""" + +__author__ = "Barry Warsaw " + +import unittest +import apt_pkg + + +class RegressionTestCase(unittest.TestCase): + + def test_no_overflow_error(self): + # LP: #1030278 produces an overflow error in size_to_str() with a big + # value under Python 3. + self.assertEqual(apt_pkg.size_to_str(2147483648000000000000), '2147 E') + + +if __name__ == "__main__": + unittest.main() + +# vim: ts=4 et sts=4 -- cgit v1.2.3 From 83d517779b4fe415005cea53a1d2d037013d8caa Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 10 Oct 2012 16:38:22 +0200 Subject: python/progress.cc: check result of Py_BuildValue() too --- python/progress.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python') diff --git a/python/progress.cc b/python/progress.cc index a7fd7ae1..9e870875 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -28,6 +28,8 @@ inline bool setattr(PyObject *object, const char *attr, const char *fmt, T arg) if (!object) return false; PyObject *value = Py_BuildValue(fmt, arg); + if (value == NULL) + return false; int result = PyObject_SetAttrString(object, attr, value); Py_DECREF(value); -- cgit v1.2.3 From 7bd938dd78ab27ec23ffd84811dbdfa5dd83593a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Oct 2012 10:09:01 +0200 Subject: * python/tag.cc: - make TagSecString_FromStringAndSize, TagSecString_FromString static, thanks to jcristau --- debian/changelog | 8 ++++++++ python/tag.cc | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/debian/changelog b/debian/changelog index 5556b294..69df3d65 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +python-apt (0.8.8.1) UNRELEASED; urgency=low + + * python/tag.cc: + - make TagSecString_FromStringAndSize, TagSecString_FromString + static, thanks to jcristau + + -- Michael Vogt Mon, 15 Oct 2012 10:03:21 +0200 + python-apt (0.8.8) unstable; urgency=low [ Program translation updates ] diff --git a/python/tag.cc b/python/tag.cc index 248d818d..6ae439f5 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -74,7 +74,7 @@ int TagFileClear(PyObject *self) { PyString_FromStringAndSize((v), (len)) #define TagSecString_FromString(self, v) PyString_FromString(v) #else -PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, +static PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, Py_ssize_t len) { TagSecData *Self = (TagSecData *)self; if (Self->Bytes) @@ -85,7 +85,7 @@ PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, return PyUnicode_FromStringAndSize(v, len); } -PyObject *TagSecString_FromString(PyObject *self, const char *v) { +static PyObject *TagSecString_FromString(PyObject *self, const char *v) { TagSecData *Self = (TagSecData *)self; if (Self->Bytes) return PyBytes_FromString(v); -- cgit v1.2.3