hampushellsberg has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/44012?usp=email )


Change subject: esim.saip: fix decoding of rfu PEs with an empty body
......................................................................

esim.saip: fix decoding of rfu PEs with an empty body

rfu1..rfu5 are PE-Dummy, an empty SEQUENCE. from_der() creates a
generic ProfileElement for them and sets the type afterwards, but the
constructor treated the empty dict like a new PE and derived a header
name from the unset type, so a profile with such a PE failed to load
with an AttributeError. Only create a header if 'decoded' is None, as
documented.

The folder osmocom-pysim-saip-empty-pe-body of
hampushellsberg-dev/PySIM-upstream-patches on GitHub has the analysis
and a repro.

Change-Id: Ic47f74e8c111643c4ba435a9bac6aa9838bd3584
---
M pySim/esim/saip/__init__.py
M tests/unittests/test_esim_saip.py
2 files changed, 18 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/12/44012/1

diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 9a1b336..e50717e 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -582,7 +582,8 @@
             pe_sequence: back-reference to the PE-Sequence of which we're part 
of
         """
         self.pe_sequence = pe_sequence
-        if decoded:
+        # PE-Dummy (rfu1..rfu5) decodes to an empty dict; only a new PE gets a 
header
+        if decoded is not None:
             self.decoded = decoded
         else:
             self.decoded = OrderedDict()
diff --git a/tests/unittests/test_esim_saip.py 
b/tests/unittests/test_esim_saip.py
index 2247d56..9d1378f 100755
--- a/tests/unittests/test_esim_saip.py
+++ b/tests/unittests/test_esim_saip.py
@@ -56,6 +56,22 @@
         pe = ProfileElement.from_der(der)
         self.assertEqual(pe.to_der(), der)

+    def test_rfu_pe(self):
+        """Test that an rfu PE (PE-Dummy, an empty SEQUENCE without header) 
decodes and re-encodes."""
+        rfu_der = asn1.encode('ProfileElement', ('rfu1', {}))
+        pe = ProfileElement.from_der(rfu_der)
+        self.assertEqual(pe.type, 'rfu1')
+        self.assertEqual(pe.to_der(), rfu_der)
+        # within a sequence: insert it before the trailing PE-End
+        tlvs = []
+        remainder = self.per_input
+        while len(remainder):
+            first_tlv, remainder = bertlv_first_segment(remainder)
+            tlvs.append(first_tlv)
+        der = b''.join(tlvs[:-1]) + rfu_der + tlvs[-1]
+        pes = ProfileElementSequence.from_der(der)
+        self.assertEqual(pes.to_der(), der)
+
     def test_sequence_helpers(self):
         """Verify that the convenience helpers worked as expected."""
         self.assertEqual([x.type for x in self.pes.pe_list], 
self.expected_pet_list)

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

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ic47f74e8c111643c4ba435a9bac6aa9838bd3584
Gerrit-Change-Number: 44012
Gerrit-PatchSet: 1
Gerrit-Owner: hampushellsberg <[email protected]>

Reply via email to