fix: reject warp configs with non-positive-integer degree
This commit is contained in:
parent
3e9878ac42
commit
f3081d36b5
2 changed files with 13 additions and 1 deletions
|
|
@ -58,4 +58,14 @@ describe('loadConfig', () => {
|
|||
const cfg = await loadConfig('config.json');
|
||||
expect(cfg.calibration).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects a warp with a non-positive-integer degree', async () => {
|
||||
const square = [[0, 0], [10, 0], [10, 10], [0, 10]] as [number, number][];
|
||||
// A negative degree makes termCount collapse to 0, so empty coeff arrays would
|
||||
// vacuously validate — guard against that.
|
||||
const warp = { degree: -1, fwd: { norm: { off: [0, 0], scl: [1, 1] }, cu: [], cv: [] }, inv: { norm: { off: [0, 0], scl: [1, 1] }, cu: [], cv: [] } };
|
||||
mockFetch({ streamUrl: 'x', calibration: { imagePoints: square, machinePoints: square, warp } });
|
||||
const cfg = await loadConfig('config.json');
|
||||
expect(cfg.calibration).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ function parsePolyMap(m: unknown, degree: number): PolyMap | null {
|
|||
function parseWarp(w: unknown): PolyWarp | null {
|
||||
if (!w || typeof w !== 'object') return null;
|
||||
const o = w as Record<string, unknown>;
|
||||
if (!isFiniteNumber(o.degree)) return null;
|
||||
// Require a positive integer degree: a negative/zero/fractional degree makes termCount
|
||||
// collapse to 0, which would vacuously accept empty coefficient arrays (a garbage warp).
|
||||
if (!isFiniteNumber(o.degree) || !Number.isInteger(o.degree) || o.degree < 1) return null;
|
||||
const fwd = parsePolyMap(o.fwd, o.degree);
|
||||
const inv = parsePolyMap(o.inv, o.degree);
|
||||
if (!fwd || !inv) return null;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue