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

Reading 24 bytes possibly results in incorrect chunks #13

Closed
dlsgusrn7577 opened this issue Nov 1, 2019 · 2 comments · Fixed by #214
Closed

Reading 24 bytes possibly results in incorrect chunks #13

dlsgusrn7577 opened this issue Nov 1, 2019 · 2 comments · Fixed by #214

Comments

@dlsgusrn7577
Copy link

I apologize in advance if this issue is a false alarm.

When reading 24 bytes in the middle and end of buffer (for method 'getEncodingSync'),
isn't it possible to get incorrectly chunked bytes?

For instance, let's say a file is consisted of 75 characters of '한', which is a Korean character represented as 3 bytes for utf8 encoding.
If we want to read middle 24 bytes, then

   chunkBegin =  Math.max(0, Math.floor(75 * 3 / 2) - chunkLength) = 88
   chunkEnd =  Math.min(75 * 3, 88 + chunkLength) = 112

However, since 88 is not multiple of 3, buffer.toString(encoding, 88, 112) will not result in the list of Korean characters '한'.

Please let me know if I am misunderstanding.
Thank you very much!

@balupton
Copy link
Member

balupton commented Nov 5, 2019

Seems plausible. Can you submit a PR that has a test that showcases this problem? Then you can update the PR with the fix (I guess flooring to the nearest 3 divisible) and we can do a release.

@sainthkh
Copy link
Contributor

sainthkh commented Jun 1, 2021

I'm currently working on this. I found error strings like:

  • 12345678901234567890123Ф
  • 1234567890123456789012안

It might take some time because I need a complete list of error cases.

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 a pull request may close this issue.

3 participants