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: Opentype allocates bunch of memory when calculating Glyph of some characters. #46836

Closed
hismailbulut opened this issue Jun 20, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hismailbulut
Copy link

hismailbulut commented Jun 20, 2021

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

$ go version
 go1.16.5 windows/amd64

Does this issue reproduce with the latest release?

I am using latest release.

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\bulut\AppData\Local\go-build
set GOENV=C:\Users\bulut\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\bulut\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\bulut\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\bulut\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\bulut\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\bulut\AppData\Local\Temp\go-build547496714=/tmp/go-build -gno-record-gcc-switches

What did you do?

I am trying to render font with using image opentype package, everything is good except one font file.
The font is an .otf font and I packed with nerdfont packer from Cascadia Mono font. After drawing some glyphs
it freezes when it comes to nerd icons. Allocates bunch of memory and not finishing 'Glyph' function. If I try with
-race option it gives this error:
==8788==ERROR: ThreadSanitizer failed to allocate 0x0001f6000000 (8422162432) bytes at 0x040094000000 (error code: 1455)

I am drawing glyph with this code:

func renderGlyph(face *font.Face, c rune) *image.RGBA {
	img := image.NewRGBA(image.Rect(0, 0, cellWidth, cellHeight))
	dot := fixed.P(0, cellHeight-descent)
	dr, mask, maskp, _, ok := face.Glyph(dot, c)
	if ok {
		draw.DrawMask(img, dr, image.White, image.Point{}, mask, maskp, draw.Over)
		return img
	}
	return nil
}

I tried font file with other programs and I don't see any issues. I can draw other fonts and characters with this
function. But only this one causing error. The base font file is original Cascadia Code and packed with nerd fonts.

This shows the usage of memory. Normally ~50 mb
Ekran görüntüsü 2021-06-20 140354

And this is the font file:
Cascadia Mono Regular Nerd Font Complete Mono Windows Compatible.zip

Edit:
I tried with same font but ttf and it's works perfectly. I don't know if this is an issue but high memory usage and not giving an error may need to be fixed.

What did you expect to see?

Just draw the font.

What did you see instead?

Memory corruption and I think a long unexpected loop.

@seankhliao seankhliao changed the title Opentype allocates bunch of memory when calculating Glyph of some characters. x/image/font: Opentype allocates bunch of memory when calculating Glyph of some characters. Jun 20, 2021
@seankhliao
Copy link
Member

can you provide a self contained, runnable example?

@gopherbot gopherbot added this to the Unreleased milestone Jun 20, 2021
@hismailbulut
Copy link
Author

I can be able to reproduce with this little test.
opentypetest.zip

@toothrot
Copy link
Contributor

/cc @nigeltao

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 21, 2021
@gopherbot
Copy link

Change https://golang.org/cl/329949 mentions this issue: font/sfnt: fix parsing PostScript fonts' 4-byte numbers

@golang golang locked and limited conversation to collaborators Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants