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

Fuzz failed round trip #407

Closed
manunio opened this issue May 9, 2024 · 6 comments
Closed

Fuzz failed round trip #407

manunio opened this issue May 9, 2024 · 6 comments

Comments

@manunio
Copy link
Contributor

manunio commented May 9, 2024

Hi, I received an oss-fuzz report with the following error message:

panic: failed round trip: toml: line 1 (last key "g"): invalid datetime: "2413-01-02T17:04:07+100:05"

The above panic was caused by fuzz target with the following input:
g=2413-01-02 17:04:07+99:65

at:

panic(fmt.Sprintf("failed round trip: %s", err))

originated here by second Decode:

toml/parse.go

Line 376 in 3203540

t, err = time.ParseInLocation(dt.fmt, it.val, dt.zone)

Can this be similar to go-toml's:
pelletier/go-toml#913

Input file:
clusterfuzz-testcase-minimized-fuzz_toml-5085441777795072.txt

@manunio manunio changed the title fuzz failed round trip Fuzz failed round trip May 12, 2024
@manunio
Copy link
Contributor Author

manunio commented May 13, 2024

Steps to Reproduce

func FuzzRound(f *testing.F) {
	f.Add([]byte("g=2413-01-02 17:04:07+99:65"))
	f.Fuzz(func(t *testing.T, data []byte) {

		t.Log("INITIAL DOCUMENT ===========================")
		t.Log(string(data))

		var v any
		_, err := Decode(string(data), &v)
		if err != nil {
			return
		}

		t.Log("DECODED VALUE ===========================")
		t.Logf("%#+v", v)

		buf := new(bytes.Buffer)
		err = NewEncoder(buf).Encode(v)
		if err != nil {
			panic(fmt.Sprintf("failed to encode decoded document: %s", err))
		}

		t.Log("ENCODED DOCUMENT ===========================")
		t.Log(buf.String())

		var v2 any
		_, err = Decode(buf.String(), &v2)
		if err != nil {
			panic(fmt.Sprintf("failed round trip: %s", err))
		}

	})
}
go test -run ^FuzzRound$ github.com/BurntSushi/toml
--- FAIL: FuzzRound (0.00s)
    --- FAIL: FuzzRound/seed#0 (0.00s)
        fuzz_test.go:85: INITIAL DOCUMENT ===========================
        fuzz_test.go:86: g=2413-01-02 17:04:07+99:65
        fuzz_test.go:94: DECODED VALUE ===========================
        fuzz_test.go:95: map[string]interface {}{"g":time.Date(2413, time.January, 2, 17, 4, 7, 0, time.Location(""))}
        fuzz_test.go:103: ENCODED DOCUMENT ===========================
        fuzz_test.go:104: g = 2413-01-02T17:04:07+100:05
            
panic: failed round trip: toml: line 1 (last key "g"): invalid datetime: "2413-01-02T17:04:07+100:05" [recovered]
        panic: failed round trip: toml: line 1 (last key "g"): invalid datetime: "2413-01-02T17:04:07+100:05"

@arp242
Copy link
Collaborator

arp242 commented May 17, 2024

It's kind of a bug in Go; let's see what comes rolling out of the bug report before I hack workarounds: golang/go#67470

@manunio
Copy link
Contributor Author

manunio commented May 20, 2024

It's kind of a bug in Go; let's see what comes rolling out of the bug report before I hack workarounds: golang/go#67470

Hi, Looks like a fix is in place: https://go.dev/cl/586717

arp242 added a commit to toml-lang/toml-test that referenced this issue May 23, 2024
@arp242
Copy link
Collaborator

arp242 commented May 23, 2024

Yes, should be fixed in Go 1.23, to be released in August.

This is such a far-out edge case I don't think it's worth doing anything more for this than adding a testcase and waiting until Go 1.23, as no one is writing offsets like "+99:65".

@arp242 arp242 closed this as completed May 23, 2024
@manunio
Copy link
Contributor Author

manunio commented May 23, 2024

Yes, should be fixed in Go 1.23, to be released in August.

Yes it has been fixed and moved to 1.23 milestone.

This is such a far-out edge case I don't think it's worth doing anything more for this than adding a testcase and waiting until Go 1.23, as no one is writing offsets like "+99:65".

You're right, but I'll have to temporarily exempt it from roundtrip error until 1.23 lands(to close this bug report which i received), as this may block fuzzers from finding more edge cases.

@arp242
Copy link
Collaborator

arp242 commented May 23, 2024

Yeah, that's fine. I don't expect I'll do another release before Go 1.23 anyway.

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

No branches or pull requests

2 participants