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

Bug: UTF-8 characters across chunk boundaries get corrupted #374

Closed
yetzt opened this issue Sep 8, 2021 · 0 comments · Fixed by #375 · May be fixed by vAHiD55555/Cross#3 or BIGboss248/V2RayAggregator#4
Closed

Bug: UTF-8 characters across chunk boundaries get corrupted #374

yetzt opened this issue Sep 8, 2021 · 0 comments · Fixed by #375 · May be fixed by vAHiD55555/Cross#3 or BIGboss248/V2RayAggregator#4

Comments

@yetzt
Copy link
Contributor

yetzt commented Sep 8, 2021

When the bytes of a UTF-8 character happen to get split across chunks when requesting a resource that is treated as text and not parsed, StreamDecoder._transform will corrupt it by applying iconv.decode on the chunk and thereby replacing the partial unicode character with a replacement character.

needle v3.0.0, reproduce:

require("needle").get("https://data.interaktiv.cloud.funkedigital.de/wahl/example/nw/erg_05994.xml", { parse: false }, function(err, resp, data){
	console.log(data.split('\n')[4379]); // line 4380
});

Suggested solutions:

  • Use iconv.decodeStream instead of iconv.decode
  • Complete chunk collection first, then use iconv.decode on complete body
  • Check if the last byte of a chunk is the first byte of a UTF-8-Character, and if so remove it from the current chunk and prepend it to the next chunk.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment