Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
795 changes: 598 additions & 197 deletions AdminPanel/server/package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions AdminPanel/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
"start": "cd .. && npm --prefix client run build && set \"NODE_CONFIG_DIR=../Common/config\" && set \"NODE_ENV=development-windows\" && node server/sources/server.js"
},
"dependencies": {
"ajv": "^8.17.1",
"ajv-errors": "^3.0.0",
"ajv-formats": "^2.1.1",
"apicache": "^1.6.3",
"config": "^3.3.11",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"express": "^4.19.2",
"ajv": "^8.17.1",
"ajv-formats": "^2.1.1",
"ajv-errors": "^3.0.0",
"joi": "^17.13.3",
"jsonwebtoken": "^9.0.2",
"ms": "^2.1.3"
"ms": "^2.1.3",
"multer": "2.2.0"
},
"pkg": {
"scripts": [
Expand Down
50 changes: 50 additions & 0 deletions AdminPanel/server/sources/routes/fonts/fontParser.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';
const {parentPort, workerData} = require('worker_threads');
const fontkit = require('fontkit');

// Fonts that are technically well-formed but structurally excessive are rejected here.
// sfnt numGlyphs/numTables are 16-bit fields; no legitimate font needs anywhere near these.
const maxTables = 64;
const maxGlyphs = 65536;
const maxCollectionFonts = 16;
const maxNameFieldLength = 256;

function truncateField(value) {
return 'string' === typeof value && value.length > maxNameFieldLength ? value.slice(0, maxNameFieldLength) : value;
}

function describeAndValidate(font) {
const numTables = font.directory ? font.directory.numTables : 0;
if (numTables > maxTables) {
throw new Error(`font declares too many tables (${numTables} > ${maxTables})`);
}
const numGlyphs = font.numGlyphs || 0;
if (numGlyphs > maxGlyphs) {
throw new Error(`font declares too many glyphs (${numGlyphs} > ${maxGlyphs})`);
}
return {
family: truncateField(font.familyName),
subfamily: truncateField(font.subfamilyName),
fullName: truncateField(font.fullName),
postscriptName: truncateField(font.postscriptName)
};
}

function openFont() {
const {mode, filePath, buffer} = workerData;
const font = 'path' === mode ? fontkit.openSync(filePath) : fontkit.create(Buffer.from(buffer));
if (Array.isArray(font.fonts)) {
// TrueType/OpenType collection (.ttc): validate every embedded font, describe the first
if (font.fonts.length > maxCollectionFonts) {
throw new Error(`font collection has too many fonts (${font.fonts.length} > ${maxCollectionFonts})`);
}
return font.fonts.map(describeAndValidate)[0];
}
return describeAndValidate(font);
}

try {
parentPort.postMessage({ok: true, result: openFont()});
} catch (err) {
parentPort.postMessage({ok: false, error: err.message});
}
Loading