Opened 3 years ago
Last modified 6 weeks ago
#33240 closed Bug
get_image_dimensions: ValueError: buffer is not large enough — at Initial Version
Reported by: | NKSM | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | 2.2 |
Severity: | Normal | Keywords: | pillow |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When I try to get the dimensions of the image like below:
def clean_image(self): image = self.cleaned_data.get("image") if not image: raise forms.ValidationError("No image!") else: w, h = get_image_dimensions(image) if w != 100: raise forms.ValidationError("The image is %i pixel wide. It's supposed to be 100px" % w) if h != 200: raise forms.ValidationError("The image is %i pixel high. It's supposed to be 200px" % h) return image
I get : ValueError: buffer is not large enough
Error at line: https://github.com/django/django/blob/073b7b5915fdfb89a144e81173176ee13ff92a25/django/core/files/images.py#L62
# Most of the time Pillow only needs a small chunk to parse the image # and get the dimensions, but with some TIFF files Pillow needs to # parse the whole file. chunk_size = 1024 while 1: data = file.read(chunk_size) if not data: break try: p.feed(data) ⬅️ **HERE** except zlib.error as e:
Exception Location: /PIL/Image.py in frombuffer, line 2605
This works well:
width, height = PillowImage.open(image).size
Note:
See TracTickets
for help on using tickets.
File to uplad