anchor_value: Fix parsing of large anchor values.

This handles the conditions when anchor values are larger than
LARGER_THAN_MAX_MESSAGE_ID by clamping them down to it.  Also added
tests for the function parse_anchor_value.

Fixes #16768.
This commit is contained in:
Sundar Guntnur
2020-11-29 01:00:02 +05:30
committed by Alex Vandiver
parent 4911bc3c4d
commit cbb7fb8ac0
2 changed files with 86 additions and 0 deletions

View File

@@ -839,6 +839,8 @@ def parse_anchor_value(anchor_val: Optional[str],
anchor = int(anchor_val)
if anchor < 0:
return 0
elif anchor > LARGER_THAN_MAX_MESSAGE_ID:
return LARGER_THAN_MAX_MESSAGE_ID
return anchor
except ValueError:
raise JsonableError(_("Invalid anchor"))