Skip to content

Commit

Permalink
Fix #117: Allow incorrectly encoded alignment bits
Browse files Browse the repository at this point in the history
If we receive incorrectly encoded alignment bits (not all 0), we simply
log it as a warning but accept it.

Signed-off-by: Abhijit Gadgil <gabhijit@iitbombay.org>
  • Loading branch information
gabhijit committed May 7, 2024
1 parent 2d09588 commit b5ee967
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions asn-compiler/src/parser/asn/structs/types/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#[derive(Debug, Clone)]
pub(crate) enum NamedValue {
Number(String),
#[allow(dead_code)]
ValueRef(String),
}

Expand Down
14 changes: 12 additions & 2 deletions codecs/src/per/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,24 @@ impl PerCodecData {
.iter()
.all(|b| b == false)
{
Err(PerCodecError::new(
// Issue 117: Sometimes the sender doesn't send the bits correctly.
// Accept it but log.
log::warn!(
"{} Padding bits {} at Offset {} not all '0'",
remaining,
&self.bits[self.decode_offset..self.decode_offset + remaining],
self.decode_offset
);
self.decode_offset += remaining;
Ok(())
/* Err(PerCodecError::new(
PerCodecErrorCause::InvalidAlignment,
format!(
"{} Padding bits at Offset {} not all '0'.",
remaining, self.decode_offset,
)
.as_str(),
))
)) */
} else {
self.decode_offset += remaining;
Ok(())
Expand Down
11 changes: 11 additions & 0 deletions examples/tests/13-ngap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ fn main() {
let mut codec_data = PerCodecData::from_slice_aper(&response_data);
let ngap_pdu = ngap::NGAP_PDU::aper_decode(&mut codec_data);
eprintln!("ngap_pdu: {:?}", ngap_pdu);

let issue_117_data: [u8; 57] = [
0x00, 0x15, 0x00, 0x35, 0x00, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x08, 0x00, 0x02, 0xf8, 0x39,
0x03, 0x80, 0x00, 0x04, 0x00, 0x52, 0x40, 0x09, 0x03, 0x00, 0x4e, 0x65, 0x72, 0x76, 0x69,
0x6f, 0x6e, 0x00, 0x66, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0xf8, 0x39,
0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x01, 0x00, 0x15, 0x40, 0x01, 0x40,
];

let mut codec_data = PerCodecData::from_slice_aper(&issue_117_data);
let ngap_pdu = ngap::NGAP_PDU::aper_decode(&mut codec_data).expect("Error decoding NGAP PDU");
eprintln!("Decoded NGAP PDU: {:#?}", ngap_pdu);
}

0 comments on commit b5ee967

Please sign in to comment.