Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux REALs ignoring WITH COMPONENTS, macOS & Windows work #134

Open
jasperswallen opened this issue Nov 27, 2021 · 3 comments
Open

Linux REALs ignoring WITH COMPONENTS, macOS & Windows work #134

jasperswallen opened this issue Nov 27, 2021 · 3 comments

Comments

@jasperswallen
Copy link

jasperswallen commented Nov 27, 2021

I've been having some very strange behavior that I seem to have tracked down to float inconsistency handling. I'm not entirely sure which implementation is correct, since I'm not an expert at reading OER ASN.1. To my untrained eye, the macOS version seems correct (8 hex digits = 32 bits), while the Linux version seems too long (20 hex digits = 80 bits). I expect the spec I wrote to hold exactly 32 bits (8 hex digits). The Linux version seems to be completely ignoring the WITH COMPONENTS argument.

Minimal reproducible code:

main.py:

import asn1tools


def main():
    spec = asn1tools.compile_files(['Spec.asn'], codec='oer')

    result = spec.encode('Example', data={'z': 0.1}, check_constraints=True)
    print(result)
    print(f"Decoded: {result.hex()}")

    decoded = spec.decode('Example', result, True)
    print(decoded)

main()

Spec.asn:

Spec DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

Float ::=
  REAL
    (WITH COMPONENTS {
       mantissa  (-16777215..16777215),
       base      (2),
       exponent  (-149..104)
     })

Example ::= SEQUENCE
{
    z Float
}

END

On macOS and Windows, I get this as the output:

➜ python3 main.py
bytearray(b'=\xcc\xcc\xcd')
Decoded: 3dcccccd
{'z': 0.10000000149011612}

On Linux, I get this as the output:

➜ python3 main.py
bytearray(b'\t\x80\xc9\x0c\xcc\xcc\xcc\xcc\xcc\xcd')
Decoded: 0980c90ccccccccccccd
{'z': 0.1}

Tested with the following environments:

  • macOS 12.1 beta, Python 3.9.9 (Homebrew), asn1tools 0.159.0 installed from wheel, WORKING
  • Kubuntu 21.04, Python 3.9.5 (apt), asn1tools 0.159.0 installed from wheel, NOT WORKING
  • Windows Server 2019 Essentials, Python 3.9.6, asn1tools 0.159.0 (also tested with 0.158.0), WORKING
  • KDE Debian 10, Python 3.7.3 (apt), asn1tools 0.159.0 installed from wheel WORKING
  • Github Actions Ubuntu NOT WORKING

I'm not sure what the common thread is here - Ubuntu-based distros seem to be an issue, but that seems unlikely to be the root cause of the issue.

@jasperswallen jasperswallen changed the title Inconsistency between Linux and macOS/Windows clients for REALs Linux REALs ignoring WITH COMPONENTS, macOS & Windows work Nov 27, 2021
@eerimoq
Copy link
Owner

eerimoq commented Nov 27, 2021

Which version of pyparsing do you have on those systems? asn1tools uses pyparsing to parse asn1-files. My guess is that asn1tools only works with pyparsing version 2.x.y, not 3.m.n.

@jasperswallen
Copy link
Author

Yup, on Kubuntu I had 3.0.6 installed. I installed 2.4.7 instead, and now it properly sizes floats!

@eerimoq
Copy link
Owner

eerimoq commented Nov 28, 2021

The latest version, 0.160.0, of asn1tools works with both old and new pyparsing. Support for old pyparsing will be dropped at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants