Skip to content

Python: reject misaligned base64 embedding payloads with a descriptive error - #9512

Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/openai-embedding-base64-alignment
Open

Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/openai-embedding-base64-alignment

Conversation

@ManoharPaturi

@ManoharPaturi Manohar Paturi (ManoharPaturi) commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

The base64 decode path sizes its unpack format as len(raw) // 4, so a payload whose decoded length is not a multiple of 4 fails inside struct.unpack with a bare buffer-size error. Nothing in the message says which input's embedding was malformed, and the error type is an internal implementation detail of the decoder.

Description & Review Guide

  • What are the major changes? The decode now checks alignment first and raises a ValueError naming the input index, the decoded byte count, and what was expected.
  • What is the impact of these changes? Well formed payloads behave exactly as before. A malformed payload now surfaces a descriptive client-facing error instead of struct.error.
  • What do you want reviewers to focus on? The test mirrors the existing base64 decoding test and feeds one well formed float plus a stray byte.

Related Issue

Fixes #9511

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

…e error

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
github-app-auth — daaa995d Deployed Oct 18, 2026 by ManoharPaturi via add_label #25694
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: malformed base64 embedding payload raises a bare struct error with no context

1 participant