[Python-checkins] cpython: Issue #19437: Fix r_PyLong() of marshal module, stop immediatly at first

victor.stinner python-checkins at python.org
Thu Oct 31 17:24:00 CET 2013


http://hg.python.org/cpython/rev/985f8762ee3e
changeset:   86807:985f8762ee3e
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Oct 31 16:56:38 2013 +0100
summary:
  Issue #19437: Fix r_PyLong() of marshal module, stop immediatly at first
failure, don't read any more data

files:
  Python/marshal.c |  15 +++++++++++----
  1 files changed, 11 insertions(+), 4 deletions(-)


diff --git a/Python/marshal.c b/Python/marshal.c
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -612,6 +612,7 @@
         }
         p->buf_size = n;
     }
+
     if (!p->readable) {
         assert(p->fp != NULL);
         read = fread(p->buf, 1, n, p->fp);
@@ -731,25 +732,31 @@
     ob = _PyLong_New(size);
     if (ob == NULL)
         return NULL;
+
     Py_SIZE(ob) = n > 0 ? size : -size;
 
     for (i = 0; i < size-1; i++) {
         d = 0;
         for (j=0; j < PyLong_MARSHAL_RATIO; j++) {
             md = r_short(p);
-            if (PyErr_Occurred())
-                break;
+            if (PyErr_Occurred()) {
+                Py_DECREF(ob);
+                return NULL;
+            }
             if (md < 0 || md > PyLong_MARSHAL_BASE)
                 goto bad_digit;
             d += (digit)md << j*PyLong_MARSHAL_SHIFT;
         }
         ob->ob_digit[i] = d;
     }
+
     d = 0;
     for (j=0; j < shorts_in_top_digit; j++) {
         md = r_short(p);
-        if (PyErr_Occurred())
-            break;
+        if (PyErr_Occurred()) {
+            Py_DECREF(ob);
+            return NULL;
+        }
         if (md < 0 || md > PyLong_MARSHAL_BASE)
             goto bad_digit;
         /* topmost marshal digit should be nonzero */

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list