#33240: get_image_dimensions: ValueError: buffer is not large enough
-------------------------------------+-------------------------------------
     Reporter:  NKSM                 |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  File                 |                  Version:  2.2
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by NKSM:

Old 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`

New 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**:

 {{{
 from PIL import Image as PillowImage
 width, height = PillowImage.open(image).size
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33240#comment:1>
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/067.f9ba178e041e73f673c754ef53b365c3%40djangoproject.com.

Reply via email to