[PR #2] [MERGED] Fixed exif saving in webp. #5

Closed
opened 2026-10-26 22:00:48 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Comfy-Org/ComfyUI-embedded-workflow-editor/pull/2
Author: @robinjhuang
Created: 3/5/2025
Status: ✅ Merged
Merged: 3/6/2025
Merged by: @snomiao

Base: main ← Head: rh-exif-fix


📝 Commits (1)

  • 5b309e3 Fixed exif saving in webp.

📊 Changes

1 file changed (+118 additions, -72 deletions)

View changed files

📝 app/utils/exif.ts (+118 -72)

📄 Description

Fix WebP EXIF Metadata Corruption

This PR addresses issues with saving EXIF metadata in WebP files that were causing file corruption. The key fixes include:

Technical Changes

  1. Fixed DataView Buffer Access: Corrected how DataViews were created and accessed when writing integers to binary data. The previous implementation was creating views with incorrect offsets, leading to buffer access errors.

  2. Added WebP Chunk Padding: WebP specification requires chunks to have even lengths. Added proper handling of padding bytes to ensure compliance with the format.

  3. Updated RIFF Size Field: Properly recalculated and updated the total file size in the RIFF header after modifications, which is critical for file integrity.

  4. Improved String Handling: Ensured proper null termination of string values in EXIF data and handled string encoding/decoding more carefully.

  5. Enhanced EXIF Header Preservation: Correctly preserved the "Exif\0\0" header when present in the original file.

Technical Background

WebP files follow the RIFF container format, which requires careful handling of chunk sizes and padding. EXIF data in WebP is stored in a specific chunk type ("EXIF") and follows the TIFF format internally. When modifying this data, we need to:

  1. Preserve the overall file structure
  2. Update length fields to reflect changes in data size
  3. Maintain proper alignment and padding
  4. Ensure binary data is written with the correct endianness

The previous implementation had issues with these requirements, particularly with how it handled buffer modifications and size calculations, which led to corrupted files.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Comfy-Org/ComfyUI-embedded-workflow-editor/pull/2 **Author:** [@robinjhuang](https://github.com/robinjhuang) **Created:** 3/5/2025 **Status:** ✅ Merged **Merged:** 3/6/2025 **Merged by:** [@snomiao](https://github.com/snomiao) **Base:** `main` ← **Head:** `rh-exif-fix` --- ### 📝 Commits (1) - [`5b309e3`](https://github.com/Comfy-Org/ComfyUI-embedded-workflow-editor/commit/5b309e3ec70658faf42744ec0a67ec2a367d4ace) Fixed exif saving in webp. ### 📊 Changes **1 file changed** (+118 additions, -72 deletions) <details> <summary>View changed files</summary> 📝 `app/utils/exif.ts` (+118 -72) </details> ### 📄 Description # Fix WebP EXIF Metadata Corruption This PR addresses issues with saving EXIF metadata in WebP files that were causing file corruption. The key fixes include: ## Technical Changes 1. **Fixed DataView Buffer Access**: Corrected how DataViews were created and accessed when writing integers to binary data. The previous implementation was creating views with incorrect offsets, leading to buffer access errors. 2. **Added WebP Chunk Padding**: WebP specification requires chunks to have even lengths. Added proper handling of padding bytes to ensure compliance with the format. 3. **Updated RIFF Size Field**: Properly recalculated and updated the total file size in the RIFF header after modifications, which is critical for file integrity. 4. **Improved String Handling**: Ensured proper null termination of string values in EXIF data and handled string encoding/decoding more carefully. 5. **Enhanced EXIF Header Preservation**: Correctly preserved the "Exif\0\0" header when present in the original file. ## Technical Background WebP files follow the RIFF container format, which requires careful handling of chunk sizes and padding. EXIF data in WebP is stored in a specific chunk type ("EXIF") and follows the TIFF format internally. When modifying this data, we need to: 1. Preserve the overall file structure 2. Update length fields to reflect changes in data size 3. Maintain proper alignment and padding 4. Ensure binary data is written with the correct endianness The previous implementation had issues with these requirements, particularly with how it handled buffer modifications and size calculations, which led to corrupted files. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-26 22:00:48 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/ComfyUI-embedded-workflow-editor#5
No description provided.