Skip to content

fix(pg-native): send Buffer parameters as bytea hex so no byte is lost - #3779

Closed
nigrosimone wants to merge 1 commit into
brianc:masterfrom
nigrosimone:fix-native-buffer-params
Closed

nigrosimone wants to merge 1 commit into
brianc:masterfrom
nigrosimone:fix-native-buffer-params

Conversation

@nigrosimone

Copy link
Copy Markdown
Contributor

Fixes #980. libpq gets every parameter as a C string, so a Buffer is read as utf8 and cut at its first zero byte: SELECT $1::bytea with dd 56 00 33 00 returns ef bf bd 56. pg sends the same Buffer in the binary format and returns it intact.

pg-native now turns a Buffer into the hex form bytea accepts, \x..., before handing the values to libpq, at every call that takes parameters: query, execute, the sync forms and the pipelined batch. Sending it in the binary format would need node-libpq to take a format per parameter, which it does not.

The added test sends a Buffer with a zero byte through a query, a prepared statement and the sync forms: it fails on master and passes here.

@nigrosimone

Copy link
Copy Markdown
Contributor Author

Closing: the hex form is right for a bytea column but wrong for a text one, and the test for #675 inserts a Buffer into a TEXT column and expects the text. Without a binary parameter format from node-libpq the two cannot both work, so the fix belongs in node-libpq.

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.

Passing a Buffer to the native bindings is not binary safe

1 participant