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

Fixed chunker chunk length calculation #680

Closed
wants to merge 5 commits into from

Conversation

dvvolynkin
Copy link

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Cookie is too large
Value not encoded before splitting.
Sometimes, this causes too big chunks because the encoded cookie value length is longer than not encoded.

What is the new behavior?

Added splitting by encoded value

@silentworks
Copy link
Contributor

Thank you for this PR. We just need to test it out and make sure the unit tests for the chunker is still passing and then we can get this merged in.

@silentworks
Copy link
Contributor

Unit tests are failing on this change, the chunk length returned is always 1 which cannot be correct.

@@ -4,7 +4,7 @@ interface Chunk {
}

function createChunkRegExp(chunkSize: number) {
return new RegExp('.{1,' + chunkSize + '}', 'g');
return new RegExp(`(.{1,${chunkSize}})(?=%[0-9A-Fa-f]{2}|$)`, 'g');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change to the Regex?

Copy link
Author

Choose a reason for hiding this comment

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

Yep, it was a mistake
Changing it back

@dvvolynkin
Copy link
Author

@silentworks
Changed regexp back, now tests are passing

Sorry that haven't checked the tests in the first commit.

@dvvolynkin
Copy link
Author

@silentworks
Added test for encoded string and fixed bug in my code

Copy link
Contributor

@silentworks silentworks left a comment

Choose a reason for hiding this comment

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

You've made too many logic change in this code, please revert the logic to what it was before as your changes are complicating the code.

@dvvolynkin
Copy link
Author

@silentworks okay

I revert all logic of chunker and leave a test that is not passing.
You can implement a logic in your style.

@dvvolynkin
Copy link
Author

dvvolynkin commented Nov 14, 2023

  1. Cookie value should be splitted into chunks that length can fit 4096 symbols after encoding.
  2. If you use the initial regexp on the encoded string then you will face that your chunks can be broken because of % sequence. (URI Malformed)

So possible solutions:

  1. Encode the string, and split the encoded string into chunks with the changed regexp that will cover the case with broken encoded sequences. Then decode chunks and return them.

  2. Encode the string, get the size, and decrease your chunk size on a divided difference, keep the rest of the initial logic.
    This will cause errors because chunk sizes are not stable in this case, some have values that will increase chunk size after encoding, and some do not.

  3. Move through the string, encode symbols, and calculate the prefix length sum of the chunk. This changes the initial logic.

  4. Split the chunk into half if its length does not fit. The easiest solution and it is quite stable but not fully. I implemented it in the last commits.

@kangmingtay
Copy link
Member

hi @dvvolynkin, thanks for working with @silentworks to hash out the possible solutions we can take to chunk the cookies correctly. just an update, we've decided to go with this approach: #726 so i'll be closing this PR

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.

3 participants