GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Large strings decoded from latin1 and then encoded to utf8 has wrong size · Issue #22728 · nodejs/node

Large strings decoded from latin1 and then encoded to utf8 has wrong size #22728

New issue
Copy link
New issue
Copy link
Closed
Closed
Large strings decoded from latin1 and then encoded to utf8 has wrong size#22728
Copy link
Labels
bufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues and PRs for confirmed bugs.encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.

Description

@henrik-ep
henrik-ep
opened on Sep 6, 2018
Issue body actions
  • Version: v8.11.4
  • Platform: Linux xyz 4.17.5-200.fc28.x86_64 deps: update openssl to 1.0.1j #1 SMP Tue Jul 10 13:39:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem:

Decoding a latin1 buffer larger than about 1MB to a string and encoding that string into utf-8 gives a buffer with the same number of bytes as the latin1 input even though more are required for characters that use more space in utf-8.

This seems to work properly on v10.x but not v8.x or v9.x.

Code that demonstrates the problem:

const fs = require('fs');
const s = 'Räksmörgås';
let ss = '';

const SIZE = (1024 * 1024);
// works:
//const SIZE = (1024 * 512);

while (ss.length < SIZE) {
    ss = ss + ss.length + ' ' + s + '\n';
}

// create latin1 buffer we can decode
let l1Buffer = Buffer.from(ss, 'latin1');
let l1String = l1Buffer.toString('latin1')
// also fixes it:
// l1String = ('x' + l1String).substring(1, l1String.length + 1);
// create utf8 buffer from decoded latin1 string
let u8Buffer = Buffer.from(l1String, 'utf8')

console.log(l1Buffer.length);
console.log(u8Buffer.length);

if (l1Buffer.length === u8Buffer.length) {
    console.log('failed, should be different size');
} else {
    console.log('works');
}

Activity

  1. jasnell
    added
    v8.x
    on Sep 6, 2018
  2. jasnell commented on Sep 6, 2018

    @jasnell
    jasnell
    on Sep 6, 2018
    Member
    More actions

    Quick test on 8.11.4 confirms the difference in behavior between Node.js 8 and 10.

    /cc @nodejs/intl @nodejs/buffer @srl295

  3. jasnell
    added
    bufferIssues and PRs related to the buffer subsystem.
    on Sep 6, 2018
  4. vsemozhetbyt
    added
    encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.
    on Sep 6, 2018
  5. addaleax
    added
    confirmed-bugIssues and PRs for confirmed bugs.
    on Sep 6, 2018
  6. addaleax commented on Sep 6, 2018

    @addaleax
    addaleax
    on Sep 6, 2018
    Member
    More actions

    This was fixed by #18216, I think.

  7. jasnell commented on Sep 6, 2018

    @jasnell
    jasnell
    on Sep 6, 2018
    Member
    More actions

    Yep, makes sense. That PR is still pending a backport to 8.x. Once the backport happens, this issue should be resolved.

  8. addaleax commented on Sep 6, 2018

    @addaleax
    addaleax
    on Sep 6, 2018
    Member
    More actions

    → Backport is in #22731

  9. addaleax
    added a commit that references this issue on Oct 2, 2018

    src: fix fs.write() externalized string handling

    590aa1f
  10. BethGriggs
    added 2 commits that reference this issue on Oct 16, 2018

    src: fix fs.write() externalized string handling

    b67bf38
  11. starkwang commented on Nov 14, 2018

    @starkwang
    starkwang
    on Nov 14, 2018
    Contributor
    More actions

    This issue is fixed in #18216 and #22731 so I'd like to close it.

  12. starkwang
    closed this as completedon Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues and PRs for confirmed bugs.encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.