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

gnovm: avoid letting malformed strings like ".-400" be passed into apd.Decimal or send patch to cockroachdb/apd #2968

Open
odeke-em opened this issue Oct 17, 2024 · 1 comment
Assignees
Labels
review/triage-pending PRs opened by external contributors that are waiting for the 1st review security Security-sensitive issue

Comments

@odeke-em
Copy link

Description

I found this bug by fuzzing with this fuzzer

package gnolang

import (
	"os"
	"path/filepath"
	"strings"
	"testing"

	"github.com/cockroachdb/apd/v3"
)

func FuzzConvertUntypedBigdecToFloat(f *testing.F) {
	// 1. Firstly add seeds.
	seeds := []string{
		"-100000",
		"100000",
		"0",
	}

	check := new(apd.Decimal)
	for _, seed := range seeds {
		if check.UnmarshalText([]byte(seed)) == nil {
			f.Add(seed)
		}
	}

	f.Fuzz(func(t *testing.T, apdStr string) {
		switch {
		case strings.HasPrefix(apdStr, ".-"):
			return
		}

		v := new(apd.Decimal)
		if err := v.UnmarshalText([]byte(apdStr)); err != nil {
			return
		}
		if _, err := v.Float64(); err != nil {
			return
		}

		bd := BigdecValue{
			V: v,
		}
		dst := new(TypedValue)
		typ := Float64Type
		ConvertUntypedBigdecTo(dst, bd, typ)
	})
}

we re-discovered a long standing bug in cockroachdb/apd cockroachdb/apd#120 (comment) let's be cautious that strings of that form will cause a panic in gnovm hence either send a fix to apd and can even use it to market gnolang and contribute positively or at least protect against such strings

@jefft0 jefft0 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 17, 2024
@kristovatlas
Copy link
Contributor

Thanks for the report, @odeke-em. We're looking into it. And extra thanks for providing the fuzzer source.

@kristovatlas kristovatlas self-assigned this Oct 29, 2024
@kristovatlas kristovatlas added the security Security-sensitive issue label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review/triage-pending PRs opened by external contributors that are waiting for the 1st review security Security-sensitive issue
Projects
None yet
Development

No branches or pull requests

3 participants