laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/39670?usp=email )

Change subject: filesystem: do not decode short TransRecEF records
......................................................................

filesystem: do not decode short TransRecEF records

A TransRecEF is based on a TransparentEF. This means that a TransRecEF
is basically normal TransparentEF that holds a record oriented data
structure. This also requires that the total length of the TransRecEF
is a multiple of the record length of the data structure that is stored
in it. When this is not the case, the last record will be cut short and
the decoding will fail. We should guard against this case.

Related: OS#6598
Change-Id: Ib1dc4d7ce306f1f0b080bb4b6abc36e72431d3fa
---
M pySim/filesystem.py
1 file changed, 12 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve




diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 246afb0..7f350ec 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -1224,6 +1224,13 @@
         Returns:
             abstract_data; dict representing the decoded data
         """
+
+        # The record data length should always be equal or at least greater 
than the record length defined for the
+        # TransRecEF. Short records may be occur when the length of the 
underlying TransparentEF is not a multiple
+        # of the TransRecEF record length.
+        if len(raw_hex_data) // 2 < self.__get_rec_len():
+            return {'raw': raw_hex_data}
+
         method = getattr(self, '_decode_record_hex', None)
         if callable(method):
             return method(raw_hex_data)
@@ -1251,6 +1258,11 @@
         Returns:
             abstract_data; dict representing the decoded data
         """
+
+        # See comment in decode_record_hex (above)
+        if len(raw_bin_data) < self.__get_rec_len():
+            return {'raw': b2h(raw_bin_data)}
+
         method = getattr(self, '_decode_record_bin', None)
         if callable(method):
             return method(raw_bin_data)

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/39670?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ib1dc4d7ce306f1f0b080bb4b6abc36e72431d3fa
Gerrit-Change-Number: 39670
Gerrit-PatchSet: 4
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>

Reply via email to