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

Fix group and type choice parsing and validation errors #121

Merged
merged 11 commits into from
Sep 12, 2022

Conversation

anweiss
Copy link
Owner

@anweiss anweiss commented Apr 19, 2022

Fixes #116 and #120.

@anweiss anweiss self-assigned this Apr 19, 2022
@anweiss anweiss added bug Something isn't working parser validation labels Apr 19, 2022
@anweiss anweiss added this to the v1.0.0 milestone Apr 19, 2022
@anweiss anweiss linked an issue Apr 19, 2022 that may be closed by this pull request
@anweiss
Copy link
Owner Author

anweiss commented Apr 19, 2022

@tomachristian feel free to give this a sanity check with some of your scenarios. Will get a separate PR up for smoke tests.

@tomachristian
Copy link

Hello @anweiss.

Thank you for this fix, it works to fix specifically that scenario, but I found one where it does not work

tester = [$$val]
$$val //= (
  type: 10,
  data: uint
)
$$val //= (
  type: 11,
  data: tstr
)

with CBOR

82           # array(2)
   0B        # unsigned(11)
   63        # text(3)
      537472 # "Str"

it fails with

  [ERROR] Validation of "/repo/.nuke/temp/ca2adc50-ef43-4301-aee2-e1ff1e0f8eb3.cbor" failed: error validating group choice group entry associated with rule "val" at cbor location : expecting array with length 1, got 2
  error validating group choice group entry associated with rule "val" at cbor location : expecting array with length 1, got 2
  error validating group choice group entry associated with rule "val" at cbor location : expecting array with length 1, got 2
  error validating group choice group entry associated with rule "val" at cbor location : expecting array with length 1, got 2
  error validating group choice group entry associated with rule "val" at cbor location : expecting array with length 1, got 2

Thank you!

@anweiss
Copy link
Owner Author

anweiss commented Apr 20, 2022

Thanks @tomachristian! Keep 'em coming! I believe I've fixed this with the most recent commit, but feel free to give it a whirl.

@anweiss anweiss force-pushed the 120-group-type-choice-parsing-validation-errors branch from c8aa8ad to 9a27fc6 Compare April 20, 2022 16:52
@anweiss
Copy link
Owner Author

anweiss commented Apr 20, 2022

Scratch that ... need to fix more of the logic here.

@anweiss
Copy link
Owner Author

anweiss commented Apr 21, 2022

@tomachristian I think I've got this fixed now

@tomachristian
Copy link

Thank you, @anweiss!

This specific scenario works, but found this:

tester = [$$val]
$$val //= (
  type: 10,
  something: uint
)

works with input

82    # array(2)
   0A # unsigned(10)
   01 # unsigned(1)

but, this

tester = [$$val]
$$val //= (
  type: 10,
  extra
)
extra = (
  something: uint
)

does NOT work with the same input.

Also, it seems that validation of float ranges requires the input to be a float, it does not work with ints event though ints are floats.

tester = -273.15..220.9

is ok with F9 4900 # primitive(18688), but not with 0A # unsigned(10).

PS: Sorry I placed everything in here, we can split them in separate issues if you want, I don't mind.

Thank you, again!

@anweiss
Copy link
Owner Author

anweiss commented May 13, 2022

Thanks @tomachristian. Working through some more fixes.

@anweiss
Copy link
Owner Author

anweiss commented Jun 27, 2022

hey @tomachristian, pushed up a couple of tweaks. Not 100% sure if I've fixed the issue, but feel free to throw some more examples at it and let me know if something still isn't working.

Also re. range validation, I interpreted the spec quite literally ... per https://datatracker.ietf.org/doc/html/rfc8610#section-2.2.2.1:

CDDL currently only allows ranges between integers (matching integer values) or between floating-point values (matching floating-point values).

Thus, if it is a floating point range, validation should only succeed against a float value that has not been coerced from an integer. CC @cabo for thoughts. Happy to move this to a Discussion as needed.

@anweiss anweiss merged commit 45442c5 into main Sep 12, 2022
@anweiss anweiss deleted the 120-group-type-choice-parsing-validation-errors branch September 12, 2022 15:20
@anweiss anweiss mentioned this pull request Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Group choices parsing error CBOR validation for type choice in array
2 participants