Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(update): survive out-of-range numeric XML entities in Atom titles (#1572)

tashdroidb8fbdab448fb
diff --git a/server/src/__tests__/routes/update.test.ts b/server/src/__tests__/routes/update.test.ts
index cc9e0fea..c4732e03 100644
--- a/server/src/__tests__/routes/update.test.ts
+++ b/server/src/__tests__/routes/update.test.ts
@@ -329,6 +329,29 @@ describe('Update API', () => {
);
});
+ it('survives out-of-range numeric XML entities in Atom titles', async () => {
+ // String.fromCodePoint throws RangeError on code points beyond
+ // 0x10FFFF; the old decoder let a remote <title> like "&#1114112;" crash
+ // the entire update check. It must degrade to leaving the entity as
+ // literal text instead.
+ const newestSha = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
+ const fetchMock = vi.fn()
+ .mockResolvedValueOnce(response({ message: 'API rate limit exceeded' }, 403))
+ .mockResolvedValueOnce(atomResponse([
+ { sha: newestSha, message: 'Fix &#1114112; and &#x110000; and &#xD800; but keep &#65;', date: '2026-07-28T13:00:00Z' },
+ { sha: LOCAL_SHA, message: 'Installed commit', date: '2026-07-28T11:00:00Z' },
+ ]));
+ const { app } = createTestApp({ fetch: fetchMock });
+
+ const result = await httpGet(app, '/api/update/check');
+
+ expect(result.status).toBe(200);
+ expect(result.body).toMatchObject({
+ status: 'available',
+ remoteMessage: 'Fix &#1114112; and &#x110000; and &#xD800; but keep A',
+ });
+ });
+
it('uses the Atom fallback to recognize the current build', async () => {
const fetchMock = vi.fn()
.mockResolvedValueOnce(response(undefined, 401))
diff --git a/server/src/routes/update.ts b/server/src/routes/update.ts
index c482e98c..b0c59955 100644
--- a/server/src/routes/update.ts
+++ b/server/src/routes/update.ts
@@ -239,12 +239,24 @@ function decodeXmlText(value: string): string {
quot: '"',
};
return value.replace(/&(?:#(\d+)|#x([0-9a-f]+)|(amp|apos|gt|lt|quot));/gi, (entity, decimal, hex, name) => {
- if (decimal) return String.fromCodePoint(Number.parseInt(decimal, 10));
- if (hex) return String.fromCodePoint(Number.parseInt(hex, 16));
+ if (decimal) return safeCodePoint(Number.parseInt(decimal, 10), entity);
+ if (hex) return safeCodePoint(Number.parseInt(hex, 16), entity);
return named[String(name).toLowerCase()] ?? entity;
});
}
+// String.fromCodePoint THROWS RangeError on anything outside 0..0x10FFFF, and
+// a lone surrogate code point produces a broken string. The input here is a
+// remote Atom feed's <title>, so a single hostile or merely malformed numeric
+// entity (&#1114112;) used to crash the whole update check. Leave the entity
+// verbatim instead — it is display text, not a hard parse dependency.
+function safeCodePoint(code: number, entity: string): string {
+ if (!Number.isFinite(code) || code < 0 || code > 0x10ffff) return entity;
+ // Lone surrogates are not valid scalar values.
+ if (code >= 0xd800 && code <= 0xdfff) return entity;
+ return String.fromCodePoint(code);
+}
+
/**
* Read a response body with a hard byte ceiling, so an oversized feed is refused
* on the way in rather than after it is already resident. Checking `.length`