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

validate the length of names #1078

Merged
merged 11 commits into from
Aug 29, 2023
Merged

validate the length of names #1078

merged 11 commits into from
Aug 29, 2023

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Aug 8, 2023

@pjfanning pjfanning marked this pull request as draft August 8, 2023 14:40
@pjfanning
Copy link
Member Author

@cowtowncoder are these changes on the right track?

_inputPtr = ptr+1; // to skip the quote
return _symbols.findSymbol(_inputBuffer, start, ptr - start, hash);
final int len = ptr - start;
_streamReadConstraints.validateNameLength(len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should only (have to) check length when adding new name in CharsToNameCanonicalizer (and byte-based counterpart); not for every time we decode a name.

But to do that would need to pass constraints... that might be doable in makeChild() method. Maybe adding new variant that takes JsonFactory, instead of flags.

@cowtowncoder
Copy link
Member

@pjfanning yes, this is pretty much along the lines I was thinking. The main concern would be trying to avoid checks for char-based names on every decoding -- seems like it'd make sense to move check into CharsToNameCanonicalizer but that requires some plumbing to pass StreamReadConstraints.

For byte/quad-based decoding I think checks on array expansion make sense; just need to pass byte-size, not quad size.

@pjfanning
Copy link
Member Author

@pjfanning yes, this is pretty much along the lines I was thinking. The main concern would be trying to avoid checks for char-based names on every decoding -- seems like it'd make sense to move check into CharsToNameCanonicalizer but that requires some plumbing to pass StreamReadConstraints.

For byte/quad-based decoding I think checks on array expansion make sense; just need to pass byte-size, not quad size.

I created #1086

@cowtowncoder
Copy link
Member

cowtowncoder commented Aug 25, 2023

Should have asked this before but... any chance to get StreamReadConstraints additions in a separate PR first, to get merged to master -- and then the rest separately?
I think the first set of changes follows a pattern and is fine as-is so I can merge this, leaving the rest easier to review (and merge too)

EDIT: I'll merge StreamReadConstraints manually, easy enough to pick.

@cowtowncoder
Copy link
Member

@pjfanning Actually, I think this is good -- I can make minor changes after merge as I see fit. So if you think this is ready, please change to regular PR from draft?

@pjfanning pjfanning marked this pull request as ready for review August 27, 2023 19:22
@pjfanning pjfanning changed the title [DRAFT] validate the length of names validate the length of names Aug 27, 2023
@pjfanning
Copy link
Member Author

@cowtowncoder should I move some of the UTF8StreamJsonParser parser checks to addName? The code there is a bit different because the ByteQuadsCanonicalizer doesn't validate the name length.

}
quads[qlen++] = currQuad;
}
_streamReadConstraints.validateNameLength(qlen << 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this could be instead moved to inside addName() which is only called if findName() does not find already canonicalized name.

Copy link
Member

@cowtowncoder cowtowncoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will merge tomorrow (merging to master/3.0 will take some time)

@cowtowncoder
Copy link
Member

@cowtowncoder should I move some of the UTF8StreamJsonParser parser checks to addName? The code there is a bit different because the ByteQuadsCanonicalizer doesn't validate the name length.

Yes, I think moving those couple of cases to only validate in addName() and not earlier would make sense.
Theoretically could refactor ByteQuadsCanonicalizer to take in validation similar to char-based one, but that's more work and not necessarily better.

@pjfanning
Copy link
Member Author

@cowtowncoder should I move some of the UTF8StreamJsonParser parser checks to addName? The code there is a bit different because the ByteQuadsCanonicalizer doesn't validate the name length.

Yes, I think moving those couple of cases to only validate in addName() and not earlier would make sense. Theoretically could refactor ByteQuadsCanonicalizer to take in validation similar to char-based one, but that's more work and not necessarily better.

I moved the check to addName().

@cowtowncoder cowtowncoder merged commit bc8433b into FasterXML:2.16 Aug 29, 2023
5 checks passed
@cowtowncoder
Copy link
Member

Thank you again @pjfanning ! This time merging to master went VERY smoothly, somehow. Good job!
I made some minor tweaks to naming but essentially implementation looks straight-forward.
Over time should add similar verification to Smile, CBOR, YAML, XML, Properties. But for now great to have it for JSON.

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

Successfully merging this pull request may close these issues.

None yet

2 participants