laforge submitted this change.

View Change

Approvals: Jenkins Builder: Verified dexter: Looks good to me, approved
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(-)

diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 86f0a39..2833fd0 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 e6f9882..4a02b71 100755
--- a/tests/unittests/test_esim_saip.py
+++ b/tests/unittests/test_esim_saip.py
@@ -47,6 +47,22 @@
self.assertEqual(reenc_tlv, first_tlv)


+ 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 change 44012. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ic47f74e8c111643c4ba435a9bac6aa9838bd3584
Gerrit-Change-Number: 44012
Gerrit-PatchSet: 2
Gerrit-Owner: hampushellsberg <hampushellsberg@gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: jolly <andreas@eversberg.eu>
Gerrit-Reviewer: laforge <laforge@osmocom.org>