Sitelet https://github.com/fresc81/node-winreg/issues/64
Skip to content

RangeError: Invalid string length #64

Description

@dss886

I have a eletron app which used this lib to get/set ProxyServer on windows and everything works fine when try get/set the reg value.

But the strange thing is that when my program runs for a while it always crashes, stacktrace as below:

RangeError: Invalid string length
    at Socket.<anonymous> (d:\Workspace\dssToolbox\node_modules\winreg\lib\registry.js:98:34)
    at Socket.emit (d:\Workspace\dssToolbox\lib\events.js:526:35)
    at addChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:324:12)
    at readableAddChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:297:9)
    at Socket.push (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:234:10)
    at Pipe.onStreamRead (d:\Workspace\dssToolbox\lib\internal\stream_base_commons.js:190:23)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {stack: 'RangeError: Invalid string length
    at Sock…Trampoline (node:internal/async_hooks:130:17)', message: 'Invalid string length'}

I located the code in registry.js,:

function captureOutput(child) {
  // Use a mutable data structure so we can append as we get new data and have
  // the calling context see the new data
  var output = {'stdout': '', 'stderr': ''};

  child.stdout.on('data', function(data) { output["stdout"] += data.toString(); });
  child.stderr.on('data', function(data) { output["stderr"] += data.toString(); });

  return output;
}

And add some log:

function captureOutput(child) {
  // Use a mutable data structure so we can append as we get new data and have
  // the calling context see the new data
  var output = {'stdout': '', 'stderr': ''};

  child.stdout.on('data', function(data) { 
    try {
        output["stdout"] += data.toString(); 
    } catch (error) {
        console.log(error);
        console.log(output["stdout"].length);
        console.log(data.toString());
        throw error;
    }
  });
  child.stderr.on('data', function(data) { output["stderr"] += data.toString(); });

  return output;
}

After crash, i got:

RangeError: Invalid string length
    at Socket.<anonymous> (d:\Workspace\dssToolbox\node_modules\winreg\lib\registry.js:98:34)
    at Socket.emit (d:\Workspace\dssToolbox\lib\events.js:526:35)
    at addChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:324:12)
    at readableAddChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:297:9)
    at Socket.push (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:234:10)
    at Pipe.onStreamRead (d:\Workspace\dssToolbox\lib\internal\stream_base_commons.js:190:23)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {stack: 'RangeError: Invalid string length
    at Sock…Trampoline (node:internal/async_hooks:130:17)', message: 'Invalid string length'}

registry.js:100
536870814
registry.js:101
ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? 

It seems that the length of the output.stdout keeps increasing until it exceeds the upper limit.

How should I solve it (or just try-catch it)?

Any help will be very appreciated.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions