Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Future releases
---------------

What's new in psycopg 2.9.12 (unreleased)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fix infinite loop with malformed interval (:ticket:`1835`).


Current release
---------------

Expand Down
7 changes: 6 additions & 1 deletion psycopg/typecast_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,12 @@ typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs)
v = v1;
}
if (part == 6) {
denom *= 10;
/* if denom would overflow it means that an excess of decimal
* digits is being pushed. Postgres should never send more than
* 6. Therefore we can quietly discard the extra. */
if (denom <= INT_MAX / 10) {
denom *= 10;
}
}
break;

Expand Down
6 changes: 6 additions & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ def test_interval_iso_8601_not_supported(self):
cur.execute("select '1 day 2 hours'::interval")
self.assertRaises(psycopg2.NotSupportedError, cur.fetchone)

def test_bug_1835(self):
for digits in (8, 31, 100):
self.assertEqual(
psycopg2.extensions.INTERVAL(b"0:0:0." + b"0" * digits, None),
timedelta(0))


class FromTicksTestCase(unittest.TestCase):
# bug "TimestampFromTicks() throws ValueError (2-2.0.14)"
Expand Down