fix: decode base64 image data before sending to Hyper3D API#194
fix: decode base64 image data before sending to Hyper3D API#194TGLEEEE wants to merge 1 commit intoahujasid:mainfrom
Conversation
…ITE mode The MCP server transmits image data as base64-encoded strings over the JSON socket connection to the Blender addon. However, the addon was passing this string directly to the requests library's `files=` parameter, which expects bytes. This caused a serialization error when calling the Hyper3D API. Fix by decoding the base64 string back to bytes before constructing the multipart form data.
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review Summary by QodoDecode base64 images before Hyper3D API submission
WalkthroughsDescription• Decode base64 image strings to bytes before API submission • Fix serialization error in Hyper3D API multipart form data • Handle both string and bytes image data types safely Diagramflowchart LR
A["Base64 image string"] -->|b64decode| B["Bytes data"]
B -->|multipart form| C["Hyper3D API request"]
D["Bytes data"] -->|passthrough| C
File Changes1. addon.py
|
Code Review by Qodo
1. Unvalidated b64decode(img) input
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
addon.py (1)
1180-1209: The base64 decoding fix is correct and addresses the API serialization issue.The change correctly decodes base64 strings to bytes before passing to
requests.files=, which expects binary data. The conditionalisinstance(img, str)properly handles both cases (base64 strings from MCP server and direct bytes).Two minor suggestions:
Type annotation mismatch: The type hint on line 1183 still says
list[tuple[str, str]], but the second element can now bestr(base64) orbytes. Consider updating for clarity.Docstring placement: The docstring on line 1189 appears after the
if images is Noneguard. It should be the first statement in the function body.,
💡 Optional: Update type hint and fix docstring placement
def create_rodin_job_main_site( self, text_prompt: str=None, - images: list[tuple[str, str]]=None, + images: list[tuple[str, str | bytes]]=None, bbox_condition=None ): + """Call Rodin API, get the job uuid and subscription key""" try: if images is None: images = [] - """Call Rodin API, get the job uuid and subscription key""" files = [🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@addon.py` around lines 1180 - 1209, In create_rodin_job_main_site, move the docstring so it is the first statement in the function body (place it immediately after the signature, before the "if images is None" guard) and update the type annotation for the images parameter to reflect that the second tuple element can be either str (base64) or bytes (e.g., use Union[str, bytes] or the bytes | str union syntax depending on project typing style); ensure any needed typing imports (Union) are added/adjusted accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@addon.py`:
- Around line 1180-1209: In create_rodin_job_main_site, move the docstring so it
is the first statement in the function body (place it immediately after the
signature, before the "if images is None" guard) and update the type annotation
for the images parameter to reflect that the second tuple element can be either
str (base64) or bytes (e.g., use Union[str, bytes] or the bytes | str union
syntax depending on project typing style); ensure any needed typing imports
(Union) are added/adjusted accordingly.
| """Call Rodin API, get the job uuid and subscription key""" | ||
| files = [ | ||
| *[("images", (f"{i:04d}{img_suffix}", img)) for i, (img_suffix, img) in enumerate(images)], | ||
| *[("images", (f"{i:04d}{img_suffix}", base64.b64decode(img) if isinstance(img, str) else img)) for i, (img_suffix, img) in enumerate(images)], |
There was a problem hiding this comment.
1. Unvalidated b64decode(img) input 📘 Rule violation ⛨ Security
The new base64.b64decode(img) path decodes external image strings without validation or explicit handling of invalid/empty/non-base64 inputs, which can raise runtime exceptions and fail the API call. This does not meet the requirement to validate external inputs and handle edge cases with actionable context.
Agent Prompt
## Issue description
`base64.b64decode(img)` is applied to external `img` strings without validation or targeted error handling, so invalid/empty/non-base64 input can raise exceptions and break Rodin job creation.
## Issue Context
`images` data comes from outside this function (socket/JSON flow per PR description), so it should be treated as untrusted input and decoded defensively.
## Fix Focus Areas
- addon.py[1186-1194] ისე
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
The MCP server transmits image data as base64-encoded strings over the JSON socket connection to the Blender addon. However, the addon was passing this string directly to the requests library's
files=parameter, which expects bytes. This caused a serialization error when calling the Hyper3D API.Fix by decoding the base64 string back to bytes before constructing the multipart form data.
Summary by CodeRabbit