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
Assignees
Milestone

Comments

@dejadejade
Copy link

@dejadejade dejadejade commented Jun 13, 2020

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

@gopherbot gopherbot commented Jun 15, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.