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

x/image/font/sfnt: Integer overflow bug #39577

Closed
dejadejade opened this issue Jun 13, 2020 · 1 comment
Closed

x/image/font/sfnt: Integer overflow bug #39577

dejadejade opened this issue Jun 13, 2020 · 1 comment

Comments

@dejadejade
Copy link

See below fix. x (GlyphIndex) is uint16, and x * 4 can easily get overflowed, this will end up returning incorrect advance or bounding box for a glyph.

diff --git a/font/sfnt/sfnt.go b/font/sfnt/sfnt.go
index b6045e7..fc782d8 100644
--- a/font/sfnt/sfnt.go
+++ b/font/sfnt/sfnt.go
@@ -1522,7 +1522,7 @@ func (f *Font) GlyphBounds(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, h font.H
                x = n
        }
 
-       buf, err := b.view(&f.src, int(f.hmtx.offset)+int(4*x), 2)
+       buf, err := b.view(&f.src, int(f.hmtx.offset)+int(x)*4, 2)
        if err != nil {
                return fixed.Rectangle26_6{}, 0, err
        }
@@ -1602,7 +1602,7 @@ func (f *Font) GlyphAdvance(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, h font.
                x = n
        }
 
-       buf, err := b.view(&f.src, int(f.hmtx.offset)+int(4*x), 2)
+       buf, err := b.view(&f.src, int(f.hmtx.offset)+int(x)*4, 2)
        if err != nil {
                return 0, err
        }

What version of Go are you using (go version)?

$ go version

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

What did you expect to see?

What did you see instead?

@gopherbot gopherbot added this to the Unreleased milestone Jun 13, 2020
@golang golang deleted a comment Jun 14, 2020
@gopherbot
Copy link

Change https://golang.org/cl/237900 mentions this issue: font/sfnt: fix uint16 overflow in Glyph{Advance,Index}

@golang golang locked and limited conversation to collaborators Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants