photostructure / exiftool-vendored.js

Fast, cross-platform Node.js access to ExifTool
https://photostructure.github.io/exiftool-vendored.js/
MIT License
431 stars 43 forks source link

Hang and then timeout on certain files #181

Closed cgatesman closed 5 months ago

cgatesman commented 5 months ago

Describe the bug

I am seeing exiftool-vendored hang on some files. I was able to isolate this to with a small example script outside of my application. The file linked below (too large to attach here) will hang if fed into the script. The exiftool command line tool, however, does not hang when executed on the file. I even tried this with the exiftool from exiftool-vendored.pl which I am using, and it does not hang.

https://drive.google.com/file/d/1jhHZL84vR159f2aWX799qvMom0qZ5jNL/view?usp=sharing

To Reproduce

import { ExifTool } from 'exiftool-vendored';
import util from 'util';

const run = async () => {
  let exiftool: ExifTool | undefined;

  try {
    exiftool = new ExifTool({ useMWG: true });

    exiftool
      .version()
      .then((version) => console.log(`Running ExifTool v${version}`));

    const tags = await exiftool?.read('ENTER_PATH_HERE/d9eb1dd0-ea74-4207-81f7-9188f5009984.jpg');
    console.log(util.inspect(tags, { showHidden: false, depth: null }));
  } catch (e) {
    console.error(e);
  } finally {
    if (exiftool) {
      await exiftool.end();
    }
  }
};

run().then(() => {});

Output:

Running ExifTool v12.82
waited 20000ms
    at BatchProcess._BatchProcess_onTimeout (/Users/chad/air/backend/node_modules/batch-cluster/src/BatchProcess.ts:493:32)
    at Timeout._onTimeout (/Users/chad/air/backend/node_modules/batch-cluster/src/BatchProcess.ts:318:30)
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7)

Expected behavior

As explained, running this script on the provided file (see link above) hangs and eventually times out after 20s, but the exiftool command line tool will not hang.

Environment (please complete the following information):

mceachen commented 5 months ago

but the exiftool command line tool will not hang.

I suspect you're not running exiftool with all of the options that this library uses:

time exiftool -json -struct -all -ignoreMinorErrors test/issue-181.jpg > out.json

real    0m24.980s
user    0m24.350s
sys 0m0.617s

And out.json is a 33 megabyte file. The photoshop:DocumentAncestors field has 792,787 items.

So: obviously, at least for that file, you don't want to -ignoreMinorErrors! ExifTool only parses the first 1000 items by default, but refuses to parse some files without that argument.

The next release will support disabling -ignoreMinorErrors via ExifToolOptions.

mceachen commented 5 months ago

v26.0.0 is released with this new option: https://photostructure.github.io/exiftool-vendored.js/interfaces/ExifToolOptions.html#ignoreMinorErrors

const { ExifTool } = require("exiftool-vendored")
new ExifTool({ ignoreMinorErrors: false }).read('evil.jpg').then(console.dir)
cgatesman commented 5 months ago

Thanks so much @mceachen for the fast turn around on this!