From 853d2bb1851c28cba766b5919eeb206e5a0dbd68 Mon Sep 17 00:00:00 2001 From: Wei Chen Date: Tue, 19 May 2026 14:08:33 -0700 Subject: [PATCH] Fix infinite recursion in win32 readProtectedFile on decrypt failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `e.message.indexOf('bad decrypt') >= -1` is always true: indexOf returns either -1 (not found) or a non-negative index, both >= -1. The intent is to detect "found", so the comparison should be `!== -1`. As written, every decrypt error — not just bad-password — clears the cached encryption key and recurses into readProtectedFile. The recursion is async so it doesn't blow the stack; the process just hangs silently awaiting a Promise that never resolves. For consumers supplying a non-interactive ui.getWindowsEncryptionPassword (which always returns the same value), this also turns a wrong-password situation into an infinite loop. Fixes #116. --- src/platforms/win32.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/win32.ts b/src/platforms/win32.ts index 94a78d7..3506a34 100644 --- a/src/platforms/win32.ts +++ b/src/platforms/win32.ts @@ -77,7 +77,7 @@ export default class WindowsPlatform implements Platform { return this.decrypt(read(filepath, 'utf8'), encryptionKey); } catch (e) { // If it's a bad password, clear the cached copy and retry - if (e.message.indexOf('bad decrypt') >= -1) { + if (e.message.indexOf('bad decrypt') !== -1) { encryptionKey = null; return await this.readProtectedFile(filepath); }