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

gdImageStringFT() fails for empty strings as of libgd 2.3.0 #615

Closed
cmb69 opened this issue Mar 26, 2020 · 6 comments
Closed

gdImageStringFT() fails for empty strings as of libgd 2.3.0 #615

cmb69 opened this issue Mar 26, 2020 · 6 comments

Comments

@cmb69
Copy link
Contributor

cmb69 commented Mar 26, 2020

When trying to render an empty string via gdImageStringFT(), the function fails as of libgd 2.3.0, while formerly it was just a no-op.

Test script

#include <stdio.h>
#include <gd.h>

int main()
{
    gdImagePtr im;
    int fg;
    int rect[8];
    char *res;

    im = gdImageCreate(100, 100);
    fg = gdImageColorAllocate(im, 255, 255, 255);
    res = gdImageStringFT(im, rect, fg, "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 12, 0, 10, 10, "");
    if (res) printf("%s\n", res);
    return 0;
}

Expected output

okay

Actual output

Problem doing text layout
@cmb69
Copy link
Contributor Author

cmb69 commented Mar 26, 2020

Forwarded from https://bugs.php.net/79415.

@cmb69
Copy link
Contributor Author

cmb69 commented May 1, 2020

The problem is that textLayout() returns 0 to signal failure, but also if an empty string is passed, although the latter is not necessarily a failure.

@willson-chen
Copy link
Member

I have no idea about how to fix this issue. Could your please offer some tips about the solution? @cmb69

cmb69 added a commit to cmb69/libgd that referenced this issue May 2, 2020
…2.3.0

We change the return type of `textLayout()` to `ssize_t`, and signal
failure by returning `-1`, so that laying out an empty string is no
longer handled as failure.  We make sure that no overflow occurs,
assuming that all `int` values can be fully represented as `ssize_t`.
@remicollet remicollet reopened this Jul 15, 2020
@remicollet
Copy link
Contributor

@cmb69 can you please have a look, it seems your patch is not enough, perhaps related to some library version.

gdImageStringFT fails with "Problem doing text layout"

@cmb69
Copy link
Contributor Author

cmb69 commented Jul 15, 2020

Is ssize_t and SSIZE_MAX available on that platform? Do you have a build with or without libraqm?

remicollet added a commit that referenced this issue Jul 15, 2020
remicollet added a commit that referenced this issue Jul 15, 2020
@remicollet
Copy link
Contributor

Do you have a build with or without libraqm?

Yes, this is related to libraqm, see pr #649

fsphil pushed a commit to fsphil/fswebcam that referenced this issue Jul 25, 2020
Since libgd 2.3.0, gdImageStringFT does not return NULL for an empty
string, thus convincing fswebcam that the font cannot be found and the
banner must be disabled.

libgd/libgd#615
Signed-off-by: Philip Heron <phil@sanslogic.co.uk>
andykimpe pushed a commit to andykimpe/remirepo that referenced this issue Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants