From 89fcc496063a7668475e52fbae4fb8ec6bac9ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurens=20St=C3=B6tzel?= Date: Tue, 21 Apr 2026 14:19:09 +0200 Subject: [PATCH] fix(sync): guard against parser errors in UDP message listener Wrap NtpPacketParser.parse() in try/catch inside the dgram message listener so a parse failure rejects the pending promise cleanly instead of escaping as an uncaughtException. This matters once the parser lands input validation (it will throw TypeError on non-48-byte or non-Buffer inputs); without this guard a single malformed UDP response would crash the host Node process. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/NtpTimeSync.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/NtpTimeSync.ts b/src/NtpTimeSync.ts index ec2392e..f2b7be2 100644 --- a/src/NtpTimeSync.ts +++ b/src/NtpTimeSync.ts @@ -385,8 +385,17 @@ export class NtpTimeSync { timeoutHandler = null; client.close(); + let parsed: Partial; + try { + parsed = NtpPacketParser.parse(msg); + } catch (err) { + hasFinished = true; + reject(err); + return; + } + const result: NtpReceivedPacket = { - ...NtpPacketParser.parse(msg), + ...parsed, destinationTimestamp: new Date(), };