Skip to content

Fall back to a default resolution when the target profile has none - #1400

Open
NilsLeo wants to merge 2 commits into
ciromattia:masterfrom
NilsLeo:up/default-resolution-fallback
Open

Fall back to a default resolution when the target profile has none#1400
NilsLeo wants to merge 2 commits into
ciromattia:masterfrom
NilsLeo:up/default-resolution-fallback

Conversation

@NilsLeo

@NilsLeo NilsLeo commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Selecting the generic 'Other'/'OTHER' device (profile resolution (0, 0)) without supplying custom width/height propagates a (0, 0) target into PIL resize/thumbnail, crashing every such conversion with a ZeroDivisionError.

This falls back to a sane default e-reader resolution (1264×1680) when the resolved profile has a zero dimension, so the generic profile no longer hard-crashes.

How to reproduce / test

Any convertible comic reproduces this — the crash is about the profile, not the file. You just need an archive that extracts cleanly and is converted with -p OTHER (no custom -u/width/height, so the target resolution stays (0, 0)).

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

Save it next to where you run the commands (referred to below as 1400.cbz). It is a plain flat CBZ of valid pages; the only thing that matters is the -p OTHER profile.

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 (-p OTHER, no custom size):

kcc ciromattia/kcc:master -p OTHER -f EPUB -o out 1400.cbz

→ aborts with ZeroDivisionError: division by zero in PIL/Image.py thumbnail (target resolution (0, 0)).

2. Same file on this branch — falls back and converts:

kcc NilsLeo/kcc:up/default-resolution-fallback -p OTHER -f EPUB -o out 1400.cbz

→ logs WARNING: profile "OTHER" has no resolution; falling back to 1264x1680, then writes a valid out/1400.epub.

Control — a real profile already works on master, confirming it is the profile and not the file:

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

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

NilsLeo and others added 2 commits July 20, 2026 00:56
Selecting the generic 'Other'/'OTHER' device (profile resolution (0,0))
without supplying custom width/height propagated a (0,0) target resolution
into PIL resize/thumbnail, crashing every such conversion with a
ZeroDivisionError. Fall back to a sane default e-reader resolution
(1264x1680) when the resolved profile has a zero dimension, and defensively
skip any genuinely zero-dimension source image during validation.
Modern Pillow raises UnidentifiedImageError when opening a zero-dimension
image, so `0 in img.size` is never reached and the check was effectively
dead code (the corrupt-image path already handles that file). Keep only the
(0, 0) target-resolution fallback, which is the reachable fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@NilsLeo

NilsLeo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

this works with any file but ive added one just in case

@NilsLeo

NilsLeo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Hey! Would it be possible to grant me Maintainer access to the repository?

I don't need to be able to push directly to main, but it would be good to have the ability to create feature branches in the repository and open PRs from those branches instead of having to work from a fork.

@axu2

axu2 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

I don't think that's needed, I personally don't do any work on ciromattia/kcc, I do everything in my fork and PR.

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.

2 participants