der: accept the documented maximum nesting depth - #2424
Open
zegroged wants to merge 1 commit into
Open
Conversation
`Position::split_nested` checks `depth < MAX_DEPTH` after incrementing a counter that starts at zero, so the 64th nested SEQUENCE is rejected with `ErrorKind::NestingDepth` while `MAX_DEPTH` is 64 and the test module describes 64 as the expected maximum. Against master this decodes 63 levels and fails on 64. Comparing with `<=` makes exactly `MAX_DEPTH` levels decode, and `MAX_DEPTH + 1` still fails. The nesting test only asserted that `MAX_DEPTH + 1` errors; nothing asserted that `MAX_DEPTH` itself succeeds, which is why this never surfaced. The message builder is now a shared helper and there is a second test for the boundary itself. That test fails on the previous code and passes with this change -- checked by running it both ways. Closes RustCrypto#2392
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the off-by-one from #2392.
Position::split_nestedincrements a counter that starts at 0 and then checksdepth < MAX_DEPTH, so the 64th nestedSEQUENCEis rejected withNestingDepthwhileMAX_DEPTHis 64 andtests/nesting.rscalls 64 "the expected maximum depth". Measured against master (7637997):Changes:
reader/position.rs:<→<=, so exactlyMAX_DEPTHlevels decode andMAX_DEPTH + 1still fails.tests/nesting.rs: the message builder is now a shared helper, and there's a new test for the boundary itself. The old test only checked that 65 errors; nothing checked that 64 succeeds, which is how this slipped through. The new test fails on the old code and passes with this change — I ran it both ways.I asked on the issue whether 64 is actually meant to be accepted (#2392 (comment)) and didn't want to sit on this waiting for an answer, so opening it now to cover both cases. If 63 is the intended ceiling, say so and I'll turn this into a comment/test fix instead of a code change.
Closes #2392