Skip to content

fix(arrow/cdata, arrow/flight): fix handling of colons in values and fix potential panics - #761

Merged
zeroshade merged 3 commits into
apache:mainfrom
thaJeztah:bug_fixes
Apr 13, 2026
Merged

zeroshade merged 3 commits into
apache:mainfrom
thaJeztah:bug_fixes

Conversation

@thaJeztah

Copy link
Copy Markdown
Contributor

fix(arrow/cdata): importSchema: handle colons in values

Use strings.Cut, both as an optimization, and to prevent values containing
a colon (e.g. "tsu:+01:00") from being mis-interpreted. This patch also
removes some intermediate variables, and redundant handling of "defaulttz",
which assigned an empty string if the value was empty.

fix(arrow/cdata): importSchema: fix potential panic and optimize

Rewrite the code with strings.Cut and strings.SplitSeq to reduce
allocations, and to fix a potential panic.

Before this patch, the code would panic if a colon was missing;

CGO_ENABLED=1 go test -v -tags test -run TestUnionSchemaErrors ./arrow/cdata/
--- FAIL: TestUnionSchemaErrors (0.00s)
    --- FAIL: TestUnionSchemaErrors/+us (0.00s)
panic: runtime error: index out of range [1] with length 1 [recovered, repanicked]

goroutine 9 [running]:
testing.tRunner.func1.2({0x7fc7c0, 0x4000026ab0})
    /usr/local/go/src/testing/testing.go:1872 +0x190
testing.tRunner.func1()
    /usr/local/go/src/testing/testing.go:1875 +0x31c
panic({0x7fc7c0?, 0x4000026ab0?})
    /usr/local/go/src/runtime/panic.go:783 +0x120
github.com/apache/arrow-go/v18/arrow/cdata.importSchema(0x40001c36d0)
    /foo/arrow/cdata/cdata.go:306 +0x1520
github.com/apache/arrow-go/v18/arrow/cdata.ImportCArrowField(...)
    /foo/arrow/cdata/interface.go:43
github.com/apache/arrow-go/v18/arrow/cdata.TestUnionSchemaErrors.func1(0x40000e0a80)
    /foo/arrow/cdata/cdata_test.go:188 +0xb0
testing.tRunner(0x40000e0a80, 0x400020c060)
    /usr/local/go/src/testing/testing.go:1934 +0xc8
created by testing.(*T).Run in goroutine 8
    /usr/local/go/src/testing/testing.go:1997 +0x364
FAIL	github.com/apache/arrow-go/v18/arrow/cdata	0.007s
FAIL

With this patch applied, the code handles the invalid value gracefully;

CGO_ENABLED=1 go test -v -tags test -run TestUnionSchemaErrors ./arrow/cdata/
=== RUN   TestUnionSchemaErrors
=== RUN   TestUnionSchemaErrors/+us
=== RUN   TestUnionSchemaErrors/+ud
--- PASS: TestUnionSchemaErrors (0.00s)
    --- PASS: TestUnionSchemaErrors/+us (0.00s)
    --- PASS: TestUnionSchemaErrors/+ud (0.00s)
PASS
ok  	github.com/apache/arrow-go/v18/arrow/cdata	0.003s

fix(arrow/flight): avoid panic on malformed authorization header

Rewrite the code with strings.Cut for readability and ensue missing credentials
in Basic/Bearer authorization headers return Unauthenticated instead of
panicking.

Before this patch, the code could panic;

go test -run TestBasicAuthMissingCredential ./arrow/flight/
panic: runtime error: index out of range [1] with length 1

goroutine 7 [running]:
github.com/apache/arrow-go/v18/arrow/flight_test.TestBasicAuthMissingCredential.CreateServerBasicAuthMiddleware.createServerBearerTokenStreamInterceptor.func3({0x8d8240, 0x40002134a0}, {0xa73e68, 0x40000e2000}, 0x40000100c0, 0x96b628)
    /foo/arrow/flight/server_auth.go:188 +0x49c
....

With this patch applied, the code handles the invalid header gracefully;

go test -run TestBasicAuthMissingCredential ./arrow/flight/
ok  	github.com/apache/arrow-go/v18/arrow/flight	0.010s

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Use strings.Cut, both as an optimization, and to prevent values containing
a colon (e.g. "tsu:+01:00") from being mis-interpreted. This patch also
removes some intermediate variables, and redundant handling of "defaulttz",
which assigned an empty string if the value was empty.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Rewrite the code with strings.Cut and strings.SplitSeq to reduce
allocations, and to fix a potential panic.

Before this patch, the code would panic if a colon was missing;

    CGO_ENABLED=1 go test -v -tags test -run TestUnionSchemaErrors ./arrow/cdata/
    --- FAIL: TestUnionSchemaErrors (0.00s)
        --- FAIL: TestUnionSchemaErrors/+us (0.00s)
    panic: runtime error: index out of range [1] with length 1 [recovered, repanicked]

    goroutine 9 [running]:
    testing.tRunner.func1.2({0x7fc7c0, 0x4000026ab0})
        /usr/local/go/src/testing/testing.go:1872 +0x190
    testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1875 +0x31c
    panic({0x7fc7c0?, 0x4000026ab0?})
        /usr/local/go/src/runtime/panic.go:783 +0x120
    github.com/apache/arrow-go/v18/arrow/cdata.importSchema(0x40001c36d0)
        /foo/arrow/cdata/cdata.go:306 +0x1520
    github.com/apache/arrow-go/v18/arrow/cdata.ImportCArrowField(...)
        /foo/arrow/cdata/interface.go:43
    github.com/apache/arrow-go/v18/arrow/cdata.TestUnionSchemaErrors.func1(0x40000e0a80)
        /foo/arrow/cdata/cdata_test.go:188 +0xb0
    testing.tRunner(0x40000e0a80, 0x400020c060)
        /usr/local/go/src/testing/testing.go:1934 +0xc8
    created by testing.(*T).Run in goroutine 8
        /usr/local/go/src/testing/testing.go:1997 +0x364
    FAIL	github.com/apache/arrow-go/v18/arrow/cdata	0.007s
    FAIL

With this patch applied, the code handles the invalid value gracefully;

    CGO_ENABLED=1 go test -v -tags test -run TestUnionSchemaErrors ./arrow/cdata/
    === RUN   TestUnionSchemaErrors
    === RUN   TestUnionSchemaErrors/+us
    === RUN   TestUnionSchemaErrors/+ud
    --- PASS: TestUnionSchemaErrors (0.00s)
        --- PASS: TestUnionSchemaErrors/+us (0.00s)
        --- PASS: TestUnionSchemaErrors/+ud (0.00s)
    PASS
    ok  	github.com/apache/arrow-go/v18/arrow/cdata	0.003s

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Rewrite the code with strings.Cut for readability and ensue missing credentials
in Basic/Bearer authorization headers return Unauthenticated instead of
panicking.

Before this patch, the code could panic;

    go test -run TestBasicAuthMissingCredential ./arrow/flight/
    panic: runtime error: index out of range [1] with length 1

    goroutine 7 [running]:
    github.com/apache/arrow-go/v18/arrow/flight_test.TestBasicAuthMissingCredential.CreateServerBasicAuthMiddleware.createServerBearerTokenStreamInterceptor.func3({0x8d8240, 0x40002134a0}, {0xa73e68, 0x40000e2000}, 0x40000100c0, 0x96b628)
        /foo/arrow/flight/server_auth.go:188 +0x49c
    ....

With this patch applied, the code handles the invalid header gracefully;

    go test -run TestBasicAuthMissingCredential ./arrow/flight/
    ok  	github.com/apache/arrow-go/v18/arrow/flight	0.010s

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
thaJeztah requested a review from zeroshade as a code owner April 12, 2026 17:27

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks!

@thaJeztah

Copy link
Copy Markdown
Contributor Author

Heh; yeah went a bit down the rabbit hole; this module is an indirect dependency in some of our code and was bringing in some transitive dependencies, so I thought; let's see what I can do there, but my branch grew a bit large, so opening smaller PRs from it to keep it reviewable.

More PRs probably incoming, but keep a good eye; I'm not very familiar with this repository 🥹☺️

@zeroshade

Copy link
Copy Markdown
Member

I appreciate it! I'll definitely keep an eye out to review them as they come in 😄

@zeroshade
zeroshade merged commit 6648c1d into apache:main Apr 13, 2026
26 of 27 checks passed
@thaJeztah
thaJeztah deleted the bug_fixes branch April 13, 2026 06:43
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

Successfully merging this pull request may close these issues.

2 participants