Skip to content

[Go] out of bounds panics in RefResolver and MetaStringResolver #3614

@ayush00git

Description

@ayush00git

Search before asking

  • I had searched in the issues and found no similar issues.

Version

0.17.0

Component(s)

Go

Minimal reproduce step

Run these tests- (just place them inside a test file and run test script)

func TestRefResolver_OOBPanic(t *testing.T) {
	resolver := newRefResolver(true) // Enable tracking
	buffer := NewByteBuffer(nil)
	
	// Craft a buffer with RefFlag (-2) followed by a huge RefID (9999)
	buffer.WriteInt8(RefFlag)
	buffer.WriteVarUint32(9999)
	buffer.SetReaderIndex(0)

	var ctxErr Error
	// This currently PANICS. The fix should prevent the panic.
	require.NotPanics(t, func() {
		resolver.ReadRefOrNull(buffer, &ctxErr)
	}, "RefResolver.GetReadObject should not panic on OOB index")
}
func TestMetaStringResolver_NegativeIndexPanic(t *testing.T) {
	resolver := NewMetaStringResolver()
	buffer := NewByteBuffer(nil)
	
	// header = 1 means (header & 1 != 0) is true (it's a reference)
	// and length = header >> 1 = 0.
	// index = length - 1 = -1.
	buffer.WriteVarUint32Small7(1)
	buffer.SetReaderIndex(0)

	var ctxErr Error
	// This currently PANICS. The fix should prevent the panic.
	require.NotPanics(t, func() {
		_, err := resolver.ReadMetaStringBytes(buffer, &ctxErr)
		if err == nil {
			// If it didn't panic, it should at least return an error
			t.Errorf("Expected error for negative index, got nil")
		}
	}, "MetaStringResolver should not panic on negative index")
}

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions