Change in pysim[master]: utils: Fix BER-TLV tag decode for multi-byte tags

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Sun Oct 24 08:28:31 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/25881 )

Change subject: utils: Fix BER-TLV tag decode for multi-byte tags
......................................................................

utils: Fix BER-TLV tag decode for multi-byte tags

We cannot simply skip anything that has 0xFF as first byte to detect
the padding after the end of a TLV object:

0xFF may very well be a valid first octet of a multi-octet TAG:

Tags of private class (11) with constructed (1) payload will have 0xFF
as first octet.

So let's expand the check to only detect padding in case of either only
a single byte FF being left, or two FF following each other [with
whatever suffix].

Change-Id: I5d64ce9ef1d973804daabae0b15c2e2349e6fab9
---
M pySim/utils.py
1 file changed, 2 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/pySim/utils.py b/pySim/utils.py
index 777638c..def88f0 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -173,7 +173,8 @@
 	Returns:
         Tuple of (tag:int, remainder:bytes)
 	"""
-	if binary[0] == 0xff:
+	# check for FF padding at the end, as customary in SIM card files
+	if binary[0] == 0xff and len(binary) == 1 or binary[0] == 0xff and binary[1] == 0xff:
 		return None, binary
 	tag = binary[0] & 0x1f
 	if tag <= 30:

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/25881
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I5d64ce9ef1d973804daabae0b15c2e2349e6fab9
Gerrit-Change-Number: 25881
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211024/ef9221ae/attachment.htm>


More information about the gerrit-log mailing list