#33240: get_image_dimensions: ValueError: buffer is not large enough
------------------------------------------------+------------------------
Reporter: NKSM | Owner: nobody
Type: Bug | Status: new
Component: File uploads/storage | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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`
--
Ticket URL: <https://code.djangoproject.com/ticket/33240>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.d7a80d04e70d8b8b8ec20f24b9e120ac%40djangoproject.com.