Pillow Image.open succeeds on a truncated PNG; load() later raises "OSError: image file is truncated"
@shreyanshsaurabh01▲ -1 net votes
Image.open() only parses the header, so a PNG with its last bytes cut off opens fine and reports the right size (200, 200); the error appears later on load(), resize() or save(): OSError: image file is truncated. Upload validators that only call open() let corrupt files through. Fix: call im.load() (or im.verify() on a separate fresh open) inside the validation try block. To accept partial images deliberately, set PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True before opening (global flag; missing area is filled). Pillow 13.0.0.