Skip to content

fix(dingtalk): transcode WebP attachments to PNG before upload - #241

Merged
ChesterRa merged 1 commit into
mainfrom
fix/dingtalk-webp-png
Dec 1, 2026
Merged

ChesterRa merged 1 commit into
mainfrom
fix/dingtalk-webp-png

Conversation

@waterbang

Copy link
Copy Markdown
Collaborator

What

DingTalk rejects WebP uploads: a WebP attachment failed at the upload stage with 40005 不合法的文件类型 and was delivered to no target. DingTalk's media upload (docs) accepts only jpg/gif/png/bmp as image and doc/docx/xls/xlsx/ppt/pptx/zip/pdf/rar as file, so sending WebP as either type cannot work.

The DingTalk sender now decodes a WebP attachment (by MIME type, .webp name, or the RIFF…WEBP signature) and uploads it as a real PNG named <name>.png with image/png. The stored attachment is unchanged. Animated WebP sends its first frame. The 10 MiB attachment limit is checked before reading and again after conversion; decoding runs on a blocking thread with a 64 MiB allocation limit. A WebP that cannot be decoded fails in the prepare stage with DingTalk WebP decode failed, before any upload or message send.

Attachment preparation moves out of dingtalk_outbound.rs into dingtalk_outbound_attachment.rs. The only new dependency is image with the png and webp features.

Verification

  • New tests through the real send_attachments path, with only the external media upload faked:
    • webp_attachment_is_sent_as_a_real_png_without_changing_the_source_blob: checks the PNG signature, the decoded 2x1 RGBA pixels including alpha, image type, overview.png, image/png, the sampleImageMsg payload, and that the source blob is unchanged.
    • invalid_webp_fails_before_upload_or_message_send.
      Both fail on the previous code and pass now; the existing DingTalk outbound tests still pass.
  • scripts/quality_gate.sh fast on this branch: clippy, workspace tests, runtime tests, daemon nextest, doc tests and tooling all pass.
  • Checked live on a DingTalk group: a WebP sent from CCCC now arrives as a viewable image.

@ChesterRa
ChesterRa merged commit d0e565b into main Dec 1, 2026
7 checks passed
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.

2 participants