kessler / node-regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
MIT License
279 stars 45 forks source link

putValue() causes uncatchable EOF exception when exception occurs near large binary values #82

Closed ctrotsky closed 1 year ago

ctrotsky commented 3 years ago

This only seems to occur when "HKCU\TestKey"'s value is a large block of binary data that is written in the same call to putValues() where another error is raised. I haven't yet narrowed down on the exact data size where this starts occurring. This occurs when the registry value causing any kind of error comes after the large value in the input to putValue().

Sample code to cause this:

process.on('uncaughtException', (err: any) => {
    console.error('Uncaught Exception: ', err);
});

export const installRegistryEntries = async (context: InstallContext) => {
    const registryValueList = fs.readJsonSync('C:\\\\Registry.json');

    try {
        await new Promise((resolve, reject) => {
            regedit.putValue(registryValueList, (err: any) => {
                if (err) {
                    console.error(`Error in callback when saving registry values: ${err}`);
                    reject(err);
                }
                console.log('Finished saving registry values');
                resolve();
            });
        });
    } catch (err) {
        // At least one value failed to install
        console.error(`Caught error when saving registry values: ${err}`);
    }
};

Output:

2020-09-09 12:31:08.967 E: [CONSOLE.ERROR] Uncaught Exception:  Error: write EOF
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16) {
  errno: 'EOF',
  code: 'EOF',
  syscall: 'write'
}
2020-09-09 12:31:08.968 E: [CONSOLE.ERROR] Error when saving registry values: Error: registry path does not exist
2020-09-09 12:31:08.969 I: [CONSOLE.LOG] Finished saving registry values
2020-09-09 12:31:08.970 E: [CONSOLE.ERROR] Caught error when saving registry values: Error: registry path does not exist

In this example,

  1. "HKCU\TestKey" is an existing registry path, and the value for this key is a large binary value.
  2. "HKCU\TestKeyThatDoesntExist" is a path that does not exist, and will lead to the "registry path does not exist" error.

File used for C:\Registry.json: https://github.com/ctrotsky/files/blob/master/Registry.json

You can see that in addition to the "registry path does not exist" error being raised in the callback, there's also a "Error: write EOF". This EOF error seems to be coming out of nowhere, and is not caught by the try/catch block.

kessler commented 2 years ago

@ctrotsky sorry for the prolonged delay. Going to take a look at this asap.

kessler commented 2 years ago

@ctrotsky it might be a problem in the communication between node and the vb script. did you manage to deduce the problematic size?

kessler commented 1 year ago

no activity