Skip to content

Commit d5616d8

Browse files
committed
Fix: Prevent crash when retrieving metadata with Sharp for many large images (Linux only)
1 parent b1a0a7c commit d5616d8

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
- Hide file extension by default [`ad33247`](https://github.com/ollm/OpenComic/commit/ad332470f47b1f110f22ee85a4384f75a19bce99)
1919
- Support playing background music on a specific page [`23aae8a`](https://github.com/ollm/OpenComic/commit/23aae8abdc8c1bd983411f0f9eeac974218694fa)
2020
- Options in OPDS to auto-download files from the catalog [`594d69f`](https://github.com/ollm/OpenComic/commit/594d69f81e3740c0be32e284dac3aed1aba69de9)
21-
- Support for tabs
21+
- Support for tabs [`d9f7fa0`](https://github.com/ollm/OpenComic/commit/d9f7fa048b743c918c44e077e0bae08705e7b8c0)
2222

2323
##### 🐛 Bug Fixes
2424

2525
- Adding or changing poster not working when the drive is different from the system drive [`8ce3d5f`](https://github.com/ollm/OpenComic/commit/8ce3d5f01a7694c26fa1e6d477c1eab99c299a0e)
2626
- Hiding cursor in fullscreen mode fails in some cases [`828d504`](https://github.com/ollm/OpenComic/commit/828d504e700e43ab1f6d9e5081195ad496f65920)
2727
- Save/Copy uses the image under the mouse cursor instead of the active page [`26c5923`](https://github.com/ollm/OpenComic/commit/26c5923d5dc920b691be5db591c20b8b92d9f320)
2828
- Error saving the progress of the final page in epub files [`ff42c18`](https://github.com/ollm/OpenComic/commit/ff42c181e7a6a324ef1065c836dc0ed175e1b623)
29+
- Prevent crash when retrieving metadata with Sharp for many large images (Linux only)
2930

3031
## [v1.6.5](https://github.com/ollm/OpenComic/releases/tag/v1.6.5) (31-10-2025)
3132

scripts/child-fork.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,21 @@ async function resizeToBlob() {
180180

181181
}
182182

183+
async function metadata() {
184+
185+
const fork = getFork();
186+
187+
return fork.work({
188+
job: 'metadata',
189+
args: [...arguments],
190+
});
191+
192+
}
193+
183194
module.exports = {
184195
ChildFork,
185196
config,
186197
_resize,
187198
resizeToBlob,
199+
metadata,
188200
};

scripts/fork.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ process.on('message', async function(data) {
5656

5757
process.send(message);
5858

59+
break;
60+
61+
case 'metadata':
62+
63+
message = {
64+
index: data.index,
65+
result: false,
66+
error: false,
67+
};
68+
69+
try
70+
{
71+
const result = await image.metadata(...data.args);
72+
message.result = result;
73+
}
74+
catch(error)
75+
{
76+
console.log(error);
77+
message.error = error.message;
78+
}
79+
80+
process.send(message);
81+
5982
break;
6083
}
6184

scripts/image.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ function loadImage(url, encode = false)
307307
});
308308
}
309309

310+
async function metadata(path)
311+
{
312+
await loadSharp();
313+
314+
const _sharp = sharp(path);
315+
return await _sharp.metadata();
316+
}
317+
310318
var sizesCache = {};
311319

312320
async function getSizes(images)
@@ -411,13 +419,11 @@ async function getSizes(images)
411419
catch(error)
412420
{
413421
const image = await workers.convertImage(path);
414-
415-
const _sharp = sharp(image);
416-
const metadata = await _sharp.metadata();
422+
const _metadata = await metadata(image);
417423

418424
size = {
419-
width: metadata.width,
420-
height: metadata.height,
425+
width: _metadata.width,
426+
height: _metadata.height,
421427
};
422428
}
423429
}
@@ -426,12 +432,13 @@ async function getSizes(images)
426432
try
427433
{
428434
fileManager.macosStartAccessingSecurityScopedResource(image.image);
429-
const _sharp = sharp(app.shortWindowsPath(image.image));
430-
const metadata = await _sharp.metadata();
435+
436+
const path = app.shortWindowsPath(image.image);
437+
const _metadata = useChildFork ? await childFork.metadata(path) : await metadata(path);
431438

432439
size = {
433-
width: metadata.width,
434-
height: metadata.height,
440+
width: _metadata.width,
441+
height: _metadata.height,
435442
};
436443
}
437444
catch(error)
@@ -460,7 +467,7 @@ async function getSizes(images)
460467
}
461468
catch(error)
462469
{
463-
console.error(error);
470+
console.error(image.image, error);
464471
}
465472

466473
sizesCache[sha] = size;
@@ -485,5 +492,6 @@ module.exports = {
485492
isAnimated: isAnimated,
486493
sharpSupportedFormat: sharpSupportedFormat,
487494
loadImage: loadImage,
495+
metadata: metadata,
488496
getSizes: getSizes,
489497
};

0 commit comments

Comments
 (0)