Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdImageGd2() writes wrong chunk sizes on boundaries #309

Closed
cmb69 opened this issue Sep 23, 2016 · 1 comment
Closed

gdImageGd2() writes wrong chunk sizes on boundaries #309

cmb69 opened this issue Sep 23, 2016 · 1 comment
Assignees
Labels

Comments

@cmb69
Copy link
Contributor

cmb69 commented Sep 23, 2016

When working on issue #288, I've noticed that gdImageGd2() writes wrong chunk sizes if the image dimensions are a multiple of the chunk size, albeit the chunks themselves are written as expected. The following program demonstrates the erroneous behavior:

#include "gd.h"
#include "gdtest.h"


int main()
{
    gdImagePtr im;
    unsigned char *buf;
    int size, word;

    im = gdImageCreate(64, 64);
    gdImageColorAllocate(im, 0, 0, 0);

    buf = gdImageGd2Ptr(im, 64, 1, &size);

    gdImageDestroy(im);

    word = buf[10] << 8 | buf[11];
    gdTestAssertMsg(word == 64, "chunk size is %d, but expected 64\n", word);
    word = buf[14] << 8 | buf[15];
    gdTestAssertMsg(word == 1, "x chunk count is %d, but expected 1\n", word);
    word = buf[16] << 8 | buf[17];
    gdTestAssertMsg(word == 1, "y chunk count is %d, but expected 1\n", word);
    gdTestAssertMsg(size == 5145, "file size is %d, but expected 5145\n", size);

    gdFree(buf);

    return gdNumFailures();
}

Output:

x chunk count is 2, but expected 1
y chunk count is 2, but expected 1
@cmb69 cmb69 added the bug label Sep 23, 2016
@cmb69 cmb69 self-assigned this Sep 23, 2016
@cmb69 cmb69 closed this as completed in bb1998a Sep 23, 2016
cmb69 added a commit that referenced this issue Sep 23, 2016
@cmb69
Copy link
Contributor Author

cmb69 commented Sep 23, 2016

FTR: reported against PHP's bundled libgd as https://bugs.php.net/73155.

orlitzky added a commit to orlitzky/php-src that referenced this issue May 17, 2023
This test uses the imagegd2() function to check that

  libgd/libgd#309

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.
nielsdos pushed a commit to php/php-src that referenced this issue Jul 6, 2023
* ext/gd/tests/bug45799.phpt: tweak to work with external gd.

The expected output from this test contains an extra newline with
gd-2.3.3 from the system (Gentoo). Adding a whitespace wildcard takes
care of it, and the test still passes with the bundled version of gd.

* ext/gd/tests: external gd-2.3.3 compatibility.

Support for the legacy "gd" image format was removed from gd-2.3.3
upstream:
  https://github.com/libgd/libgd/blob/master/CHANGELOG.md#233---2021-09-12

Several tests for the gd extension utilize that format, and naturally
fail when gd-2.3.3 from the system is used. This commit skips those
tests when the version of gd is at least 2.3.3.

* ext/gd/tests/bug73159.phpt: skip with external gd >= 2.3.3

This test uses the imagegd2() function to check that
  libgd/libgd#289

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.

* ext/gd/tests/bug73155.phpt: skip with external gd >= 2.3.3

This test uses the imagegd2() function to check that
  libgd/libgd#309

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.

* ext/gd/tests/bug73157.phpt: skip with external gd >= 2.3.3

This test ensures that the third (chunk_size) parameter to imagegd2()
is respected when a fourth parameter is also given. However, when an
external gd without support for the "gd" format is used, the call to
imagegd2() does not really work at all. It doesn't fail, but it
produces an "image" with a nonsense chunk size.

To avoid failures when an external gd >= 2.3.3 is used, we skip the
test entirely in that case.

* ext/gd/tests/bug77973.phpt: accept lowercase "Invalid"

This test fails with an external gd because the test expects "Invalid"
where upstream gd says "invalid". This commit tweaks the expected
output to accept an arbitrary character in the i/I position.

* ext/gd/tests/bug39780_extern.phpt: update for external gd-2.3.3.

Since there are no CI runs with external gd, I can only assume that
this test has fallen out-of-date due to changes in PHP itself. I've
tweaked the expected output (only slightly) so that the test passes
with both gd-2.3.2 and gd-2.3.3.

* ext/gd/tests/bug66356.phpt: update expected output for external gd.

Newer (external) versions of GD start their error messages with
lowercase characters, whereas this test is expecting them in
uppercase. A single-character wildcard now supports both formats.

* ext/gd/tests/imagegd_truecolor.phpt: skip with external gd >= 2.3.3.

This test uses the imagegd() function, but the "gd" format has been
disabled by default in upstream gd-2.3.3. We still get some kind of
image data back from the call to imagegd(), but its "signature",
"truecolor", and "size" no longer match the expected values. This
commit skips the test when an external gd >= 2.3.3 is used.

* ext/gd/tests/createfromwbmp2_extern.phpt: update for external gd-2.3.3.
* ext/gd/tests/libgd00086_extern.phpt: update for external gd-2.3.3.

Since there are no CI runs with external gd, I can only assume that
this test has fallen out-of-date due to changes in PHP itself. I've
tweaked the expected output (only slightly) so that the test passes
with both gd-2.3.2 and gd-2.3.3.

* ext/gd/tests/bug77272.phpt: update expected output for external gd.

Newer (external) versions of GD start their error messages with
lowercase characters, whereas this test is expecting them in
uppercase. A single-character wildcard now supports both formats.

* ext/gd/tests/bug77479.phpt: update for newer external gd.

This test fails with gd-2.3.3 (at least) due to minor capitalization
and whitespace issues. We add some wildcards to account for the
difference.

Closes GH-11257.
Closes GH-11262.
Closes GH-11264.
Closes GH-11280.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant