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
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def deserialize_encryption_context(serialized_encryption_context):

dict_size, deserialized_size = read_short(source=serialized_encryption_context, offset=deserialized_size)
_LOGGER.debug("Found %d keys", dict_size)
if dict_size == 0:
raise SerializationError("Formatting error: Serialized context contains no entries.")
for _ in range(dict_size):
key_size, deserialized_size = read_short(source=serialized_encryption_context, offset=deserialized_size)
key, deserialized_size = read_string(
Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_encryption_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ def test_deserialize_encryption_context_duplicate_key(self):
)
excinfo.match("Duplicate key in serialized context.")

def test_deserialize_encryption_context_zero_entries(self):
"""Reject a nonempty serialized encryption context with zero entries."""
data = b"\x00\x00"
with pytest.raises(SerializationError) as excinfo:
aws_encryption_sdk.internal.formatting.encryption_context.deserialize_encryption_context(
serialized_encryption_context=data
)
excinfo.match("Formatting error: Serialized context contains no entries.")

def test_deserialize_encryption_context_extra_data(self):
"""Validate that the deserialize_encryption_context
function behaves as expected when it encounters
Expand Down