Skip to content

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

Closed
@yetzt

Description

@yetzt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions