From 2ada767e7654440f86d6a96d6afb24c22d0002f7 Mon Sep 17 00:00:00 2001 From: spilin Date: Mon, 24 Jan 2022 16:19:58 +0200 Subject: [PATCH] Avoid BUFFER_OVERRUN for unsupported revert reason #165 (#171) --- lib/utils.js | 8 ++++++-- src/utils.ts | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index a62abc32..68edb30b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -44,8 +44,12 @@ export function parseEVMRevertReason(reason) { if (reason.length > 0) { // only for valid decoded revert reason const coder = new ethers.utils.AbiCoder(); - const result = coder.decode(['string'], reason.slice(4)); - return result.toString(); + try { + return coder.decode(['string'], reason.slice(4)).toString(); + } + catch { + return reason; + } } return reason; } diff --git a/src/utils.ts b/src/utils.ts index 9a359cab..22610f83 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -79,8 +79,11 @@ export function parseEVMRevertReason(reason: Uint8Array): string | Uint8Array { if (reason.length > 0) { // only for valid decoded revert reason const coder = new ethers.utils.AbiCoder(); - const result = coder.decode(['string'], reason.slice(4)); - return result.toString(); + try { + return coder.decode(['string'], reason.slice(4)).toString(); + } catch { + return reason; + } } return reason; }