diff options
author | Harald Welte <laforge@osmocom.org> | 2023-12-08 16:08:53 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2023-12-17 10:46:31 +0000 |
commit | b3c46135bb87893d504750ceadfb32df2b17cff2 (patch) | |
tree | e19353daf355b44f826005df31cdd4c3df7aabc5 | |
parent | 6e9ae8a5847dd725671898290ba5147aeebde906 (diff) |
bertlv_parse_len: Fix input data is smaller than num length octets
This can happen if there's a file with invalid encoding on the card,
such as a tag followed by all-ff. Let's gracefully ignore it and
return zero bytes as response.
Change-Id: Ic44557368a6034dbf4bb021ab23a57927c22def0
-rw-r--r-- | pySim/utils.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py index 44800fb..23b26f9 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -314,6 +314,8 @@ def bertlv_parse_len(binary: bytes) -> Tuple[int, bytes]: else: num_len_oct = binary[0] & 0x7f length = 0 + if len(binary) < num_len_oct + 1: + return (0, b'') for i in range(1, 1+num_len_oct): length <<= 8 length |= binary[i] |