Skip to content
Open
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ Contributors (chronological)
- Dhruvil Darji `@dhruvildarji <https://github.com/dhruvildarji>`_
- Haïm Dimer `@hdimer <https://github.com/hdimer>`_
- `@vidigoat <https://github.com/vidigoat>`_
- Keshav Tibrewal `@keshtib07-ghost <https://github.com/keshtib07-ghost>`_
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

4.4.1 (unreleased)
------------------

Bug fixes:

- Raise `ValidationError <marshmallow.exceptions.ValidationError>` for
overflowing RFC date components and integer POSIX timestamps when loading
`DateTime <marshmallow.fields.DateTime>` fields.

4.4.0 (2026-11-03)
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/marshmallow/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ def _deserialize(self, value, attr, data, **kwargs) -> _D:
if func:
return func(value)
return self._make_object_from_format(value, data_format)
except (TypeError, AttributeError, ValueError) as error:
except (TypeError, AttributeError, ValueError, OverflowError) as error:
raise self.make_error(
"invalid", input=value, obj_type=self.OBJ_TYPE
) from error
Expand Down
41 changes: 40 additions & 1 deletion tests/test_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,52 @@ def test_boolean_timestamp_field_deserialization(self, fmt, in_value):
@pytest.mark.parametrize("fmt", ["timestamp", "timestamp_ms"])
@pytest.mark.parametrize(
"in_value",
["", "!@#", -1],
[
"",
"!@#",
-1,
pytest.param(10**400, id="oversized-positive-integer"),
pytest.param(-(10**400), id="oversized-negative-integer"),
],
)
def test_invalid_timestamp_field_deserialization(self, fmt, in_value):
field = fields.DateTime(format=fmt)
with pytest.raises(ValidationError, match="Not a valid datetime."):
field.deserialize(in_value)

@pytest.mark.parametrize(
"field_class", [fields.DateTime, fields.NaiveDateTime, fields.AwareDateTime]
)
@pytest.mark.parametrize("fmt", ["rfc", "rfc822"])
@pytest.mark.parametrize(
"value",
[
"Fri, 31 Dec 999999999999999999 23:59:59 +0000",
"Thu, 31 Dec 2026 999999999999999999:59:59 +0000",
],
ids=["oversized-year", "oversized-hour"],
)
def test_rfc_datetime_overflow_is_validation_error(self, field_class, fmt, value):
field = field_class(format=fmt)
with pytest.raises(ValidationError, match="Not a valid datetime."):
field.deserialize(value)

@pytest.mark.parametrize("method", ["load", "validate"])
def test_schema_reports_rfc_datetime_overflow(self, method):
class EventSchema(Schema):
when = fields.DateTime(format="rfc")

schema = EventSchema()
data = {"when": "Fri, 31 Dec 999999999999999999 23:59:59 +0000"}
expected = {"when": ["Not a valid datetime."]}

if method == "validate":
assert schema.validate(data) == expected
else:
with pytest.raises(ValidationError) as excinfo:
schema.load(data)
assert excinfo.value.messages == expected

# Regression test for https://github.com/marshmallow-code/marshmallow/pull/2102
@pytest.mark.parametrize("fmt", ["timestamp", "timestamp_ms"])
@pytest.mark.parametrize(
Expand Down