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

UnhandledRejection due to Unexpected end of input #366

Open
sk- opened this issue Feb 20, 2021 · 6 comments
Open

UnhandledRejection due to Unexpected end of input #366

sk- opened this issue Feb 20, 2021 · 6 comments
Labels

Comments

@sk-
Copy link

sk- commented Feb 20, 2021

Describe the bug

When running reg-cli with a bunch of rendered images I get an UnhandledRejection error and the application freezes. I realized that empty pngs trigger this, which I was able to solve by first deleting those files. But it also seems that corrupt files also trigger the error. I'm not sure which file is triggering the error.

Reproduced step

Steps to reproduce the behavior:

  1. Add an empty png file to the source folder.

Expected behavior

Invalid image files should not crash or hand the process.

Actual behavior

(node:49896) UnhandledPromiseRejectionWarning: Error: Unexpected end of input
    at module.exports.ChunkStream._end (/usr/local/lib/node_modules/reg-cli/node_modules/pngjs/lib/chunkstream.js:92:24)
    at module.exports.ChunkStream.end (/usr/local/lib/node_modules/reg-cli/node_modules/pngjs/lib/chunkstream.js:81:10)
    at exports.PNG.PNG.end (/usr/local/lib/node_modules/reg-cli/node_modules/pngjs/lib/png.js:100:16)
    at ReadStream.onend (_stream_readable.js:677:10)
    at Object.onceWrapper (events.js:421:28)
    at ReadStream.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1224:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:49896) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:49896) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@sk- sk- added the bug label Feb 20, 2021
@sk- sk- changed the title UnhandledRejection UnhandledRejection due to Unexpected end of input Feb 20, 2021
@sk-
Copy link
Author

sk- commented Feb 20, 2021

I checked all the files with both file and identify -verbose and they all look like valid PNGs. My gut feeling is that one of those files is incomplete, but I have no way to know which file is the one causing the issue.

There is a reported issue for the pngjs dependency. It seems that the parser is too strict and does not recover from errors. See pngjs/pngjs#209.

@sk-
Copy link
Author

sk- commented Feb 20, 2021

I think the issue may be here, because imgDiff and createDiff can be rejected.

reg-cli/src/diff.js

Lines 76 to 78 in 3f4935d

process.on('message', (data) => {
createDiff(data);
});

@sk-
Copy link
Author

sk- commented Feb 22, 2021

FWIW i had to use the following script to find the offending file:

const fs = require('fs');
const { PNG } = require('pngjs');

const filename = process.argv[2];
const png = new PNG();
fs.createReadStream(filename)
  .pipe(png)
  .on('parsed', () => {
    console.log(`Successfully parsed ${filename}`);
  })
  .on('error', (error) => {
    console.log(error);
    console.error(`Error parsing PNG-file: ${filename}!`);
  });

@bokuweb
Copy link
Member

bokuweb commented Feb 22, 2021

@sk- Thanks!! If you are ok, could you please provide your invalid files to reproduce in my env.

@sk-
Copy link
Author

sk- commented Feb 22, 2021

@bokuweb Unfortunately I don't have the files anymore. But It seemed like a truncated png file as when I opened it, it showed only half of it.

Note that an empty file with a .png extension will trigger the same issue.

@bokuweb
Copy link
Member

bokuweb commented Feb 22, 2021

@sk- I see, I'll try it later. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants