Skip to content

Conversation

@ljluestc
Copy link
Contributor

fix(contrib/drivers/pgsql): preserve bytea data containing 0x5D

Bug Description

Fixes issue #4231 where PostgreSQL bytea fields containing the byte 0x5D (ASCII ]) were being forcibly converted to 0x7D (ASCII }), causing data corruption and image parsing failures.

Root Cause

The ConvertValueForField function in contrib/drivers/pgsql/pgsql_convert.go was applying array syntax conversion ([{, ]}) to all slice types, including binary data intended for bytea fields. This conversion is only appropriate for PostgreSQL array types, not binary data.

Changes Made

  • Modified: contrib/drivers/pgsql/pgsql_convert.go
    • Added check for []byte with bytea field type before applying array conversion
    • Preserves binary data integrity for bytea fields
  • Added: contrib/drivers/pgsql/pgsql_z_unit_issue_4231_test.go
    • Regression test that inserts and retrieves binary data containing 0x5D
    • Verifies data integrity is maintained throughout the round-trip

Integration test (requires PostgreSQL)

cd contrib/drivers/pgsql
go test -v -run Test_Issue4231

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.

1 participant