From caa8dbe691934cc344b0e3fa7314c0282430da8c Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:36:58 -0500 Subject: [PATCH] Use DelimitedStream in backup validator Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> --- ts/services/backups/validator.preload.ts | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ts/services/backups/validator.preload.ts b/ts/services/backups/validator.preload.ts index 1a773fc70b..7cbf50f043 100644 --- a/ts/services/backups/validator.preload.ts +++ b/ts/services/backups/validator.preload.ts @@ -1,19 +1,17 @@ // Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import type { Readable } from 'node:stream'; -import { once } from 'node:events'; +import { type Readable, PassThrough } from 'node:stream'; +import { pipeline } from 'node:stream/promises'; import * as libsignal from '@signalapp/libsignal-client/dist/MessageBackup.js'; import type { InputStream } from '@signalapp/libsignal-client/dist/io.js'; -import protobufjs from 'protobufjs'; import { strictAssert } from '../../util/assert.std.js'; import { toAciObject } from '../../util/ServiceId.node.js'; import { missingCaseError } from '../../util/missingCaseError.std.js'; +import { DelimitedStream } from '../../util/DelimitedStream.node.js'; import { itemStorage } from '../../textsecure/Storage.preload.js'; -const { Reader } = protobufjs; - export enum ValidationType { Export = 'Export', Internal = 'Internal', @@ -62,14 +60,16 @@ export async function validateBackupStream( let totalBytes = 0; let frameCount = 0; - const allErrorMessages: Array = []; - readable.on('data', delimitedFrame => { - totalBytes += delimitedFrame.byteLength; - frameCount += 1; - const reader = new Reader(delimitedFrame); - const frame = reader.bytes(); + const countBytes = new PassThrough(); + countBytes.on('data', bytes => { + totalBytes += bytes.byteLength; + }); + + const delimited = new DelimitedStream(); + delimited.on('data', frame => { + frameCount += 1; // Info frame if (frameCount === 1) { @@ -88,7 +88,8 @@ export async function validateBackupStream( } }); - await once(readable, 'end'); + await pipeline(readable, countBytes, delimited); + strictAssert(validator != null, 'no frames'); try {