






















@@ -307,8 +307,36 @@ export function extractHtmlFromAttachment(att: MSTeamsAttachmentLike): string |
307307return text;
308308}
309309310-function isLikelyBase64Payload(value: string): boolean {
311-return /^[A-Za-z0-9+/=\r\n]+$/.test(value);
310+function canonicalizeInlineBase64Payload(value: string): string | undefined {
311+let cleaned = "";
312+let padding = 0;
313+let sawPadding = false;
314+for (let index = 0; index < value.length; index += 1) {
315+const code = value.charCodeAt(index);
316+if (code <= 0x20) {
317+continue;
318+}
319+if (code === 0x3d) {
320+padding += 1;
321+if (padding > 2) {
322+return undefined;
323+}
324+sawPadding = true;
325+cleaned += "=";
326+continue;
327+}
328+const isDataChar =
329+(code >= 0x41 && code <= 0x5a) ||
330+(code >= 0x61 && code <= 0x7a) ||
331+(code >= 0x30 && code <= 0x39) ||
332+code === 0x2b ||
333+code === 0x2f;
334+if (sawPadding || !isDataChar) {
335+return undefined;
336+}
337+cleaned += value[index];
338+}
339+return cleaned && cleaned.length % 4 === 0 ? cleaned : undefined;
312340}
313341314342function decodeDataImageWithLimits(
@@ -325,11 +353,12 @@ function decodeDataImageWithLimits(
325353return { candidate: null, estimatedBytes: 0 };
326354}
327355const payload = match[3] ?? "";
328-if (!payload || !isLikelyBase64Payload(payload)) {
356+const canonicalPayload = canonicalizeInlineBase64Payload(payload);
357+if (!canonicalPayload) {
329358return { candidate: null, estimatedBytes: 0 };
330359}
331360332-const estimatedBytes = estimateBase64DecodedBytes(payload);
361+const estimatedBytes = estimateBase64DecodedBytes(canonicalPayload);
333362if (estimatedBytes <= 0) {
334363return { candidate: null, estimatedBytes: 0 };
335364}
@@ -338,7 +367,7 @@ function decodeDataImageWithLimits(
338367}
339368340369try {
341-const data = Buffer.from(payload, "base64");
370+const data = Buffer.from(canonicalPayload, "base64");
342371return {
343372candidate: { kind: "data", data, contentType, placeholder: "<media:image>" },
344373 estimatedBytes,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。