Skip to content

fix(sdk): normalize image upload media types before decoding - #5747

Draft
Kayvan-Zahiri wants to merge 1 commit into
bentoml:mainfrom
Kayvan-Zahiri:codex/image-upload-mime-parameters
Draft

Kayvan-Zahiri wants to merge 1 commit into
bentoml:mainfrom
Kayvan-Zahiri:codex/image-upload-mime-parameters

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

What does this PR address?

An image upload with Content-Type: image/png; charset=binary sends PNG; CHARSET=BINARY to Pillow as a format name and fails. Split off MIME parameters and normalize the case of the media type before selecting the Pillow decoder. Keep restricting the decoded image to the declared format.

Closes #5746.

Eight regression/control cases use real PNG/JPEG bytes and Starlette uploads. On the original code, four fail and five existing/control cases pass. With this fix, all 10 tests under tests/unit/_bentoml_sdk pass.

Also exercised a local @bentoml.api HTTP endpoint accepting PIL.Image.Image. The same PNG upload returns HTTP500 on the original tree and HTTP200 with [2, 3] after the fix. These are local ASGI requests; no BentoCloud/Modular deployment was used.

Before submitting:

  • Does the Pull Request follow Conventional Commits specification naming?
  • Does the code follow BentoML's code style, pre-commit run -a script has passed? Changed-file pre-commit checks passed: Ruff lint/format, trailing whitespace, EOF. The whole-repository -a run was not performed; lock/buf hooks had no applicable changed files.
  • Did you read through contribution guidelines and follow development guidelines? Dependencies installed into an isolated Python3.11 venv using uv.
  • Did your changes require updates to the documentation? No new API or documented argument was introduced.
  • Did you write tests to cover your changes?

AI assistance: Codex investigated, implemented and ran the checks above on Kayvan's behalf. No unaided human review or full repository test run is claimed. This draft is ready for maintainer feedback.

This branch has not been deployed

No deployments
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.

bug: image uploads with Content-Type parameters fail in Pillow decoder

1 participant