librasn / rasn

A Safe #[no_std] ASN.1 Codec Framework
Other
183 stars 43 forks source link

Comparing Object Identifier causes SIGSEGV #228

Closed Byter09 closed 3 months ago

Byter09 commented 4 months ago

Hello!

First of all, I would like to thank all contributors for this crate. It is amazing.

I'm in the process of switching our manual ASN decoders to using rasn, and am currently moving MMS (ISO 9506-1 and 2). One of the carrier protocols is ACSE (ISO 8650), which is also ASN and I already ported it over.

While trying to figure out if ACSE is transporting MMS, I'm looking at a "application context name" which is a ObjectIdentifier.

My initial code to compare the value is like this:

if request.application_context_name != [1_u32, 0, 9506, 2, 3][..] { ... }

Upon testing this, my stack kept overflowing. I thought maybe I had some recursion, but the more I debugged it, the more it became clear. The comparison is actually the problem: grafik

Specifically, this code in oid.rs:

impl PartialEq<[u32]> for ObjectIdentifier {
    fn eq(&self, rhs: &[u32]) -> bool {
        self == rhs
    }
}

I managed to fix this by either dereferncing the field

if *request.application_context_name != [1_u32, 0, 9506, 2, 3][..] { ... }

or using the Oid type directly:

if request.application_context_name != Oid::const_new(&[1_u32, 0, 9506, 2, 3]) {

The rasn version used is 0.12.5 with a Rust compiler version of 1.69.0.

So, I am not sure if this is considered a bug, but it caused confusion :D

On an unrelated note, the rasn_compiler struggles to eat all the specifications I tried so far, but nevertheless, good job on that one. I tried simpler ASN and it was so much fun to see the output be basically what I'd write myself. Writing over 6000 lines of code for the MMS one by hand wasn't fun though :D

XAMPPRocky commented 4 months ago

Thank you for your issue! The fix is pretty simple I believe, self needs to be deref'ed or otherwise mad a slice before comparing.

Byter09 commented 3 months ago

Fixed in 0.12.6 :) https://github.com/librasn/rasn/pull/223 Sorry for the duplicate.