Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

QQ platform occasionally sends image messages with file: "base64://" containing no actual base64 data. The bot would decode this empty string, create a 0-byte file, re-encode it as empty base64, and send data:image/jpeg;base64, to the LLM API, causing Error 500: "base64 string is empty".

Changes

Validation at decode points

  • Image.convert_to_file_path() and convert_to_base64(): Raise ValueError if base64 data is empty after prefix removal
  • Record: Same validation for consistency
  • openai_source.encode_image_bs64(): Return empty string with warning for empty base64

Error handling

  • llm_request.py: Catch ValueError from convert_to_file_path(), log warning, skip invalid images
  • LLM requests continue with remaining valid content

Example flow

# Before: Creates empty file, sends malformed data to API
image = Image(file="base64://")
await image.convert_to_file_path()  # Returns path to 0-byte file → Error 500

# After: Fails fast with clear error
await image.convert_to_file_path()  # ValueError: Base64 data is empty for image: base64://
# Handler logs: "跳过无效图片: Base64 data is empty..." and continues

Fixes #3239

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.soulter.top
    • Triggering command: /home/REDACTED/work/AstrBot/AstrBot/.venv/bin/python /home/REDACTED/work/AstrBot/AstrBot/.venv/bin/pytest tests/ -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

#3239
修复这个issue


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 1, 2025 18:01
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
@LIghtJUNction LIghtJUNction requested a review from Copilot November 1, 2025 18:05
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds validation to prevent empty base64 data from causing issues in image processing. When base64:// prefixes are removed but leave empty strings, the code now properly detects and handles these cases.

Key changes:

  • Added empty base64 data validation checks across image and record handling methods
  • Added error handling in LLM request processing to gracefully skip invalid images
  • Enhanced error messages to include context about which image/record failed

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
astrbot/core/message/components.py Added empty base64 validation checks in Record and Image classes' convert_to_file_path() and convert_to_base64() methods
astrbot/core/pipeline/process_stage/method/llm_request.py Wrapped image path conversion in try-except to gracefully handle ValueError from invalid images
astrbot/core/provider/sources/openai_source.py Added empty base64 validation in encode_image_bs64() method with warning log and early return

Comment on lines 476 to +484
bs64_data = bs64_data.removeprefix("base64://")
if not bs64_data:
raise ValueError(f"Base64 data is empty for image: {url}")
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file_to_base64() function always returns strings prefixed with "base64://", so after removing the prefix on line 482, bs64_data can never be empty (it will always contain the base64-encoded content). This validation check is unreachable and will never trigger. The validation should occur before calling file_to_base64() or should validate the actual data content length.

Copilot uses AI. Check for mistakes.
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue related to AstrBot functionality Fix Error 500 on multimodal input with empty base64 image data Nov 1, 2025
Copilot finished work on behalf of LIghtJUNction November 1, 2025 18:10
Copilot AI requested a review from LIghtJUNction November 1, 2025 18:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@LIghtJUNction LIghtJUNction requested a review from Copilot November 1, 2025 18:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

@LIghtJUNction LIghtJUNction requested a review from Copilot November 1, 2025 18:22
@LIghtJUNction LIghtJUNction marked this pull request as ready for review November 1, 2025 18:22
@auto-assign auto-assign bot requested review from Fridemn and Larch-C November 1, 2025 18:22
@LIghtJUNction LIghtJUNction self-requested a review November 1, 2025 18:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

LIghtJUNction and others added 2 commits November 2, 2025 03:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@LIghtJUNction LIghtJUNction deleted the copilot/fix-issue-3239 branch November 7, 2025 07:36
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]多模态输入失败:图片 Base64 字符串为空 (Error 500)

2 participants