Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid throwing of runtime exception if DTXMessage cannot be decoded #184

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
15 changes: 12 additions & 3 deletions lib/instrument/transformer/dtx-decode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Stream from 'stream';
import { DTX_MESSAGE_HEADER_LENGTH, DTX_MESSAGE_HEADER_MAGIC, DTX_MESSAGE_HEADER_MAGIC_LEN,
DTXMessageHeader, DTXMessage} from '../headers';
import {
DTX_MESSAGE_HEADER_LENGTH, DTX_MESSAGE_HEADER_MAGIC, DTX_MESSAGE_HEADER_MAGIC_LEN,
DTXMessageHeader, DTXMessage,
} from '../headers';
import log from '../../logger';

class DTXDecoder extends Stream.Transform {

Expand Down Expand Up @@ -49,7 +52,13 @@ class DTXDecoder extends Stream.Transform {
data = this._dtxManager[this.header.channel];
delete this._dtxManager[this.header.channel];
if (data) {
this.push(DTXMessage.parse(data.headerBuffer, data.payloadBuffer));
try {
const dtxMessage = DTXMessage.parse(data.headerBuffer, data.payloadBuffer);
this.push(dtxMessage);
} catch (e) {
log.debug(e.stack);
log.error(`Skipped decoding of an unparseable DTXMessage: ${e.message}`);
}
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions lib/instrument/transformer/nskeyed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import bplistCreate from 'bplist-creator';
import { parse as uuidParse, stringify as uuidStringify } from 'uuid';
import _ from 'lodash';
import { format as stringFormat } from 'node:util';
import log from '../../logger';

const NSKEYED_ARCHIVE_VERSION = 100_000;
// @ts-ignore UID is not exposed to typedefs
Expand Down Expand Up @@ -371,16 +372,22 @@ class Unarchive {

unpackArchiveHeader() {
const plist = plistlib.parseBuffer(this.input)[0];
const createPlistIssue = (/** @type {string} */ message) => {
try {
log.debug(`Source plist: ${_.truncate(JSON.stringify(plist), {length: 250})}`);
} catch (ign) {}
return new Error(message);
};
if (plist.$archiver !== NSKEYEDARCHIVER) {
throw new Error(`unsupported encoder: ${plist.$archiver}`);
throw createPlistIssue(`unsupported encoder: ${plist.$archiver}`);
}
if (plist.$version !== NSKEYED_ARCHIVE_VERSION) {
throw new Error(`expected ${NSKEYED_ARCHIVE_VERSION}, got ${plist.$version}`);
throw createPlistIssue(`expected ${NSKEYED_ARCHIVE_VERSION}, got ${plist.$version}`);
}
const top = plist.$top;
const topUID = top.root;
if (!topUID) {
throw new Error(`top object did not have a UID! dump: ${JSON.stringify(top)}`);
throw createPlistIssue(`top object did not have a UID! dump: ${JSON.stringify(top)}`);
}
this.topUID = topUID;
this.objects = plist.$objects;
Expand Down
Loading