Skip to content

Commit 1c061d6

Browse files
committed
fix: validate TIFF dimensions before decoding and correct .tif MIME type
Move MAX_PIXEL_COUNT check before UTIF.decodeImage/toRGBA8 so oversized TIFFs are rejected before allocating the RGBA buffer. Map .tif extension to image/tiff in Content_Types.xml generation to avoid emitting the invalid MIME type image/tif.
1 parent 5f0832d commit 1c061d6

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

packages/super-editor/src/core/DocxZipper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DocxZipper {
9696
async updateContentTypes(docx, media, fromJson, updatedDocs = {}) {
9797
const additionalPartNames = Object.keys(updatedDocs || {});
9898
const imageExts = new Set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'tif', 'emf', 'wmf', 'svg', 'webp']);
99+
const mimeTypeForExt = { tif: 'tiff' };
99100
const newMediaTypes = Object.keys(media)
100101
.map((name) => this.getFileExtension(name))
101102
.filter((ext) => ext && imageExts.has(ext));
@@ -121,7 +122,8 @@ class DocxZipper {
121122
if (defaultMediaTypes.includes(type)) continue;
122123
if (seenTypes.has(type)) continue;
123124

124-
const newContentType = `<Default Extension="${type}" ContentType="image/${type}"/>`;
125+
const mime = mimeTypeForExt[type] || type;
126+
const newContentType = `<Default Extension="${type}" ContentType="image/${mime}"/>`;
125127
typesString += newContentType;
126128
seenTypes.add(type);
127129
}

packages/super-editor/src/core/super-converter/v3/handlers/wp/helpers/tiff-converter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ export function convertTiffToPng(data) {
9090
const ifds = UTIF.decode(buffer);
9191
if (!ifds || ifds.length === 0) return null;
9292

93+
// Validate dimensions from IFD metadata before decoding pixel data
94+
const { width, height } = ifds[0];
95+
if (!width || !height || width * height > MAX_PIXEL_COUNT) return null;
96+
9397
// Decode pixel data for the first page
9498
UTIF.decodeImage(buffer, ifds[0]);
9599
const rgba = UTIF.toRGBA8(ifds[0]);
96100
if (!rgba || rgba.length === 0) return null;
97101

98-
const { width, height } = ifds[0];
99-
if (!width || !height || width * height > MAX_PIXEL_COUNT) return null;
100-
101102
// Render to canvas and export as PNG
102103
const canvas = createCanvas();
103104
if (!canvas) {

0 commit comments

Comments
 (0)