Skip to content

Skip corrupt pages instead of aborting the whole conversion - #1399

Open
NilsLeo wants to merge 1 commit into
ciromattia:masterfrom
NilsLeo:up/image-resilience
Open

Skip corrupt pages instead of aborting the whole conversion#1399
NilsLeo wants to merge 1 commit into
ciromattia:masterfrom
NilsLeo:up/image-resilience

Conversation

@NilsLeo

@NilsLeo NilsLeo commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

A single unreadable or zero-byte page raised RuntimeError and failed the entire book, even when every other page was fine. This skips the bad page and carries on, while keeping a genuine environment error (a missing Pillow decoder) fatal so real setup problems still surface. It also guards against a missing cover, so a damaged archive with no usable cover page no longer crashes with a NoneType error.

How to reproduce / test

A comic with one zero-byte page and one unreadable/garbage page mixed in with valid pages triggers both fatal branches this PR fixes:

Download: https://drive.google.com/file/d/1rz38SkzJLcZ3D_laJCdC8XYo5nRg9Ghi/view?usp=drive_link

Save it next to where you run the commands (referred to below as 1399.cbz). The archive is flat (images at the root) with page-003-EMPTY.jpg (0 bytes) and page-005-GARBAGE.jpg (non-image bytes) between valid pages.

The easiest way to A/B test any KCC branch without a local setup is kcc-run, which clones a given owner/repo:ref into a throwaway container at runtime:

export DOCKER_DEFAULT_PLATFORM=linux/amd64   # Apple Silicon; no-op on Intel/AMD
kcc() { docker run --platform linux/amd64 --rm -v "$PWD:/work" -w /work ghcr.io/nilsleo/kcc-run "$@"; }

1. Reproduce the crash on upstream master (one corrupt page fails the whole book):

kcc ciromattia/kcc:master -p KV -f EPUB -o out 1399.cbz

→ aborts with RuntimeError: Image file .../page-005-GARBAGE.jpg is corrupted. at detectSuboptimalProcessing; no EPUB produced.

2. Same file on this branch — skips the bad pages and converts the rest:

kcc NilsLeo/kcc:up/image-resilience -p KV -f EPUB -o out 1399.cbz

→ logs

WARNING: Skipping corrupt image .../page-005-GARBAGE.jpg (cannot identify image file ...)
WARNING: Skipping corrupt (empty) image .../page-003-EMPTY.jpg

then writes a valid out/1399.epub from the remaining pages.

(Or clone this branch and run python kcc-c2e.py -p KV -f EPUB -o out 1399.cbz directly.)

A single unreadable or zero-byte page raised RuntimeError and failed the
entire book, even when every other page was fine. Skip the bad page and
carry on; keep only the genuine environment error (missing Pillow decoder)
as fatal. Also guard against a missing cover so a damaged archive with no
usable cover page no longer crashes with a NoneType error.
@NilsLeo

NilsLeo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@axu2 this is constructed, but ive encountered files like this several times that have these sort of corrupted pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant