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 and improve the check for maximum element size #68

Merged
merged 4 commits into from
Dec 22, 2023

Conversation

chrzaszcz
Copy link
Member

@chrzaszcz chrzaszcz commented Dec 21, 2023

The original option named max_child_size had two major issues:

  1. It only checked incomplete (chunked) elements
  2. It also checked the stream opening tag

They are both addressed:

  1. Added a check for complete elements as well. The check prevents constructing the Erlang term.
  2. Modified the option name to max_element_size. When infinite_stream is used, the elements are not children anyway. The size of the stream-opening tag is still checked, but it is documented now. One could (maliciously or not) send a huge stream-opening tag, so the check makes sense.

Other changes:

  • Updated error messages.
  • The check for incomplete elements was failing too soon - one more character should be accepted. Now at most max_element-size - 1 characters are accepted, because we know that at least one more character will be parsed.
  • Removed unused obsolete options from tests.

Recommended for the future: add OTP 26 to CI.

@codecov-commenter
Copy link

codecov-commenter commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (aa62735) 71.85% compared to head (b9500bd) 72.12%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #68      +/-   ##
==========================================
+ Coverage   71.85%   72.12%   +0.27%     
==========================================
  Files           7        7              
  Lines        1112     1123      +11     
  Branches      163      166       +3     
==========================================
+ Hits          799      810      +11     
  Misses        313      313              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chrzaszcz chrzaszcz force-pushed the max-element-size branch 2 times, most recently from c9997a2 to 25bd9bd Compare December 21, 2023 14:02
The original option named 'max_child_size' had two major issues:
1. It only checked incomplete (chunked) elements
2. It also checked the stream opening tag

Ad 1: Added a check for complete elements as well.
The check prevents constructing the Erlang term.

Ad 2: Modified the option name to 'max_element_size', and made it
check the size of the stream-opening tag as well as sizes of any
element. This makes sense because:
- One could (maliciously or not) send a huge stream-opening tag
- When infinite_stream is used, the elements are not children anyway,
  so the name was misleading.

Other changes:
- Updated error messages.
- The check for incomplete elements was failing too soon - one more
  character should be accepted. Now at most max_element-size-1
  characters are accepted, because we know that at least one more
  character will be parsed.
@chrzaszcz chrzaszcz marked this pull request as ready for review December 22, 2023 07:37
Copy link

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

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

Love it! 🔥

@NelsonVides NelsonVides merged commit 74263a9 into master Dec 22, 2023
5 checks passed
@NelsonVides NelsonVides deleted the max-element-size branch December 22, 2023 09:51
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

3 participants