惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
MyScale Blog
MyScale Blog
博客园 - 【当耐特】
I
InfoQ
腾讯CDC
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
C
Check Point Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
D
Docker
MongoDB | Blog
MongoDB | Blog
量子位
博客园_首页

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(agents): catch malformed image blocks in sanitizeCont...
LowCode191 · 2026-06-14 · via Recent Commits to openclaw:main

@@ -7,7 +7,11 @@ import {

77

createTinyJpegBuffer,

88

} from "../../test/helpers/image-fixtures.js";

99

import { getImageMetadata } from "../media/image-ops.js";

10-

import { sanitizeContentBlocksImages, sanitizeImageBlocks } from "./tool-images.js";

10+

import {

11+

sanitizeContentBlocksImages,

12+

sanitizeImageBlocks,

13+

sanitizeToolResultImages,

14+

} from "./tool-images.js";

11151216

describe("tool image sanitizing", () => {

1317

const getImageBlock = (

@@ -117,6 +121,83 @@ describe("tool image sanitizing", () => {

117121

expect(image.data).toBe(jpeg.toString("base64"));

118122

});

119123124+

it("preserves data and mimeType on no-resize path", async () => {

125+

const png = createSolidPngBuffer(10, 10, { r: 0, g: 0, b: 255 });

126+

const base64 = png.toString("base64");

127+128+

const blocks = [{ type: "image" as const, data: base64, mimeType: "image/png" }];

129+

const out = await sanitizeContentBlocksImages(blocks, "test");

130+

expect(out).toHaveLength(1);

131+

const image = getImageBlock(out);

132+

expect(typeof image.data).toBe("string");

133+

expect(image.data.length).toBeGreaterThan(0);

134+

expect(typeof image.mimeType).toBe("string");

135+

expect(image.mimeType).toBe("image/png");

136+

});

137+138+

it("preserves data and mimeType on resize path", async () => {

139+

const png = createSolidPngBuffer(2600, 400, { r: 255, g: 0, b: 0 });

140+

const base64 = png.toString("base64");

141+142+

const blocks = [{ type: "image" as const, data: base64, mimeType: "image/png" }];

143+

const out = await sanitizeContentBlocksImages(blocks, "test");

144+

expect(out).toHaveLength(1);

145+

const image = getImageBlock(out);

146+

expect(typeof image.data).toBe("string");

147+

expect(image.data.length).toBeGreaterThan(0);

148+

expect(typeof image.mimeType).toBe("string");

149+

}, 20_000);

150+151+

it("converts image blocks with missing data/mimeType to text", async () => {

152+

const blocks = [

153+

{

154+

type: "image" as const,

155+

data: undefined as unknown as string,

156+

mimeType: undefined as unknown as string,

157+

},

158+

];

159+

const out = await sanitizeContentBlocksImages(blocks, "browser:screenshot");

160+

expect(out).toHaveLength(1);

161+

expect(out[0].type).toBe("text");

162+

expect((out[0] as { type: "text"; text: string }).text).toContain("missing data or mimeType");

163+

});

164+165+

it("screenshot-shaped tool result round-trips with valid image block", async () => {

166+

const png = createSolidPngBuffer(100, 100, { r: 0, g: 128, b: 0 });

167+

const base64 = png.toString("base64");

168+169+

const result = {

170+

content: [{ type: "image" as const, data: base64, mimeType: "image/png" }],

171+

details: { path: "/tmp/screenshot.png" },

172+

};

173+

const sanitized = await sanitizeToolResultImages(result, "browser:screenshot");

174+

const imageBlock = sanitized.content.find((b) => b.type === "image");

175+

expect(imageBlock).toBeDefined();

176+

expect(typeof (imageBlock as { data: string }).data).toBe("string");

177+

expect((imageBlock as { data: string }).data.length).toBeGreaterThan(0);

178+

expect(typeof (imageBlock as { mimeType: string }).mimeType).toBe("string");

179+

});

180+181+

it("screenshot-shaped tool result with malformed image produces text fallback", async () => {

182+

const result = {

183+

content: [

184+

{

185+

type: "image" as const,

186+

data: undefined as unknown as string,

187+

mimeType: undefined as unknown as string,

188+

},

189+

],

190+

details: {},

191+

};

192+

const sanitized = await sanitizeToolResultImages(result, "browser:screenshot");

193+

const imageBlocks = sanitized.content.filter((b) => b.type === "image");

194+

expect(imageBlocks).toHaveLength(0);

195+

const textFallback = sanitized.content.find(

196+

(b) => b.type === "text" && (b as { text: string }).text.includes("missing data or mimeType"),

197+

);

198+

expect(textFallback).toBeDefined();

199+

});

200+120201

it("drops malformed image base64 payloads", async () => {

121202

// Invalid base64 is replaced with text so malformed payloads cannot smuggle

122203

// attributes or script-like text through image blocks.