Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#25038 closed defect (bug) (fixed)

imagecreatetruecolor fails when WP tries to make image with width of 0

Reported by: patrelentlesstechnologycom's profile pat@… Owned by: nacin's profile nacin
Milestone: 3.7 Priority: normal
Severity: major Version: 2.5
Component: Media Keywords: has-patch
Focuses: Cc:

Description

Uploading a tall narrow image will cause an error when trying to upload. I've uploaded an image with dimensions 4x1640, and when WP generates image sizes it's trying to create an image at 0x300 which throws an error in 'imagecreatetruecolor'.

I'd expect WP to skip an attempt to create an image with invalid dimensions.

No relevant plugins installed that would affect this. Problem may exist at other image ratios as well.

Attachments (3)

bgrepeat.jpg (1.4 KB) - added by pat@… 11 years ago.
Sample image
25038.patch (1.6 KB) - added by plocha 11 years ago.
Path for both bugs
25038.diff (1.3 KB) - added by jeremyfelt 11 years ago.

Download all attachments as: .zip

Change History (8)

@pat@…
11 years ago

Sample image

#1 @markoheijnen
11 years ago

  • Milestone changed from Awaiting Review to 3.7

Thanks for the example image. Really curious why it would return 0 width.

#2 @plocha
11 years ago

  • Keywords has-patch needs-testing added
  • Version changed from 3.6 to trunk

The problem is the scaling code. If you try to scale a 2x20 image with the ratio 0.25, you will get a 0.5x5 image. We use integers, so we get a 0x5 image in this example. We should round up image sizes with 0px. I further fixed an equivalent bug in the preview generation of the image editor.

Maybe we should reorganize the code to avoid the redundant scaling code.

Last edited 11 years ago by plocha (previous) (diff)

@plocha
11 years ago

Path for both bugs

#3 @SergeyBiryukov
11 years ago

  • Version changed from trunk to 2.5

@jeremyfelt
11 years ago

#4 @jeremyfelt
11 years ago

  • Keywords needs-testing removed

plocha's patch works well. I refreshed in 25038.diff with an updated inline comment about the check for a minimum of 1. Also removed an unnecessary change from $w = $max_width; to $w++;. No reason for not doing it that way, but the diff reads cleaner without it.

#5 @nacin
11 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 25744:

Make sure when resizing an image according to ratio we do not end up with a zero-pixel width or height.

props plocha.
fixes #25038.

Note: See TracTickets for help on using tickets.