Azure / Azure/azure-functions-sql-extension

SQL Output Binding to Binary column fails when "/" character is in the BASE64 String

Open
#1,176 3 comments 0 reactions 1 assignee Assigned to @MaddyDev View on GitHub
bug
Dominant language
C#
Stars
130
Forks
71
Avg merge
4d 8h
Merged PRs (30d)
4

Description

- Azure Functions SQL Extension or Extension Bundle Version:
Azure Functions Core Tools
Core Tools Version: 4.0.7030 Commit hash: N/A +bb4c949899cd5659d6bfe8b92cc923453a2e8f88 (64-bit)
Function Runtime Version: 4.1037.0.23568
- Is this a deployed or local function: Local and Deployed
- What type of Database are you using? Microsoft SQL Azure (RTM) - 12.0.2000.8 Apr 9 2025 07:13:50 Copyright (C) 2024 Microsoft Corporation 5

Steps to Reproduce:

1. `CREATE TABLE BinaryData (BinaryColumn binary(8))`
2. Attempt to send the following JSON string to the output binding for the above table: '{"BinaryColumn":"//////////8="}'
3. This should result in the binary value 0xFFFFFFFFFFFFFFFF being inserted into the table. Instead an error is returned:

> Base64 encoded string cannot be converted to binary value. Binary data would be truncated.

This only occurs when a "/" character exists in the BASE64 string. This is because the output binding framework tries to run the following command, escaping "/" characters in the whole JSON object.

`SELECT * FROM OPENJSON(REPLACE(@rowData, N'/', N'\/')) WITH ([BinaryColumn] binary(8))`

Manually running the above SQL, but doubling the length to binary(16) avoids the error.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.