Skip to content

github.com/gogf/gf/v2/util/gvalid: valid binary field,a large amount of memory is consumed #4092

@redwolf2019

Description

@redwolf2019

Go version

go version go1.23.2 darwin/arm64

GoFrame version

2.7.4

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

package main

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gfile"
	"github.com/gogf/gf/v2/os/gproc"
)

func main() {
	in := &Model{Raw: gfile.GetBytes("/Users/redwolf/Downloads/50MB.zip")}

	if err := g.Validator().Data(in).Run(context.Background()); err != nil {
		g.Log().Fatal(context.Background(), err)
	}

	gproc.Listen()
}

type Model struct {
	Raw []byte `v:"required"`
}

image

When I validate a 50MB []byte field, the actual memory usage approaches 1GB.

What did you see happen?

High memory usage with delayed garbage collection.

What did you expect to see?

It shouldn't consume this much memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIt is confirmed a bug, but don't worry, we'll handle it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions