Skip to content

QueryFontMetrics nil pointer panic fix#333

Merged
justinfx merged 1 commit intogographics:masterfrom
jackharrhy:fix-query-font-metrics
Feb 16, 2026
Merged

QueryFontMetrics nil pointer panic fix#333
justinfx merged 1 commit intogographics:masterfrom
jackharrhy:fix-query-font-metrics

Conversation

@jackharrhy
Copy link
Copy Markdown
Contributor

gographics/imagick@760c816 (v3.5.3, #309) added a GetLastError() check, but the C functions can return NULL without setting an error — e.g. when Freetype is not compiled in.

cdoubles := C.MagickQueryFontMetrics(mw.mw, dw.dw, cstext)
if err := mw.GetLastError(); err != nil { // NULL + no error → passes through
    return nil
}
defer relinquishMemory(unsafe.Pointer(cdoubles))
doubles := sizedDoubleArrayToFloat64Slice(cdoubles, 13) // <- panic: nil deref

Same issue in QueryMultilineFontMetrics.

Fix

Add an explicit nil check on cdoubles after the existing error check.

[gographics/imagick@760c816](gographics@760c816)
(v3.5.3, [gographics#309](gographics#309)) added
a `GetLastError()` check, but the C functions can return NULL *without*
setting an error - e.g. when Freetype is not compiled in.

This fixes that.
@justinfx
Copy link
Copy Markdown
Member

Thank you for submitting a PR for your report! I'll get this merged and can tag it tomorrow

@justinfx justinfx merged commit 73d5ec8 into gographics:master Feb 16, 2026
1 check failed
justinfx pushed a commit that referenced this pull request Feb 16, 2026
[760c816](760c816)
(v3.5.3, [#309](#309)) added
a `GetLastError()` check, but the C functions can return NULL *without*
setting an error - e.g. when Freetype is not compiled in.

This fixes that.
@justinfx
Copy link
Copy Markdown
Member

Tagged v2.7.1 / v3.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants