fix(video): zero-trust metadata on fast-upload group video

The width/height=0 → 文件已过期 fix only covered the normal upload path, which
ffprobes real dimensions from the video bytes. The fast-upload (fingerprint /
forward) path has NO bytes to probe, so every field it ships is caller-supplied
and untrusted — a video that arrived on the wire without metadata caches 0s, and
re-forwarding it then shipped width/height=0 (receiver renders 文件已过期) and
time=0 (every client renders 00:00).

Harden videoPayloadFromFingerprint so no degenerate value reaches the wire:
- width/height fall back with `||` (not `??`, so a cached 0 is replaced too);
- duration falls back the same way (0 → 1, never 00:00);
- the fallback cover is now a real 720x1280 image, and the fallback video/cover
  dimensions are derived FROM it (detectImageFormat), so the declared video size,
  the declared cover size and the actual cover pixels are the same numbers by
  construction — never a 1x1 image lying about its size.

Real cached values always win; c2c is unaffected (the wire builder forces 0 for
c2c). Verified on-target by forwarding a zeroed video (renders, not expired).
This commit is contained in:
DrSmoothl committed 2026-07-05 18:10:05 +08:00
1 parent ac20956076
commit e1e0c6b02f
2 files changed
+54 -16

No files matched your search

@@ -140,6 +140,39 @@ describe('video-upload', () => {
expect((c2cInfo[0] as any).fileInfo.height).toBe(0);
});
it('[#145] zero-trust: fallback cover declared dims equal the video fallback (content == declared)', async () => {
// The fast-upload cover is a real 720x1280 image; the thumb sub-file must
// declare those same pixels, not a 1x1 lying about its size, and they match
// the video fallback so tile + cover agree.
const noDims = { ...FINGERPRINT, width: 0, height: 0 } as any;
await uploadVideoMsgInfo({} as any, true, 12345, noDims);
const info = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploadInfo;
expect((info[0] as any).fileInfo.width).toBe(720); // video tile
expect((info[0] as any).fileInfo.height).toBe(1280);
expect((info[1] as any).fileInfo.width).toBe(720); // cover sub-file (subFileType 100)
expect((info[1] as any).fileInfo.height).toBe(1280);
});
it('[#145] zero-trust: cached duration 0 → time 1, never 00:00', async () => {
const noDur = { ...FINGERPRINT, duration: 0 } as any;
await uploadVideoMsgInfo({} as any, true, 12345, noDur);
const info = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploadInfo;
expect((info[0] as any).fileInfo.time).toBe(1);
});
it('[#145] real video dims are preserved on the main file even though the cover is the 720x1280 fallback', async () => {
// FINGERPRINT has real 320x240 dims; the fast-upload cover is always the
// 720x1280 fallback (no real cover cached on the forward path). The video
// tile keeps the real dims — the cover/tile aspect mismatch is tolerated,
// only a 0x0 MAIN file triggers 文件已过期.
await uploadVideoMsgInfo({} as any, true, 12345, FINGERPRINT);
const info = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploadInfo;
expect((info[0] as any).fileInfo.width).toBe(320); // main video: real dims preserved
expect((info[0] as any).fileInfo.height).toBe(240);
expect((info[1] as any).fileInfo.width).toBe(720); // cover: fallback
expect((info[1] as any).fileInfo.height).toBe(1280);
});
it('main video carries the real `time` (duration in seconds) — regression: was 0', async () => {
// NTV2 server bakes the `time` field into the resulting MsgInfo
// bytes that ride along as `commonElem.pbElem`; the receiver