diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/ScriptChunk.java b/src/main/java/com/sparrowwallet/drongo/protocol/ScriptChunk.java index ce559a1..bf05d97 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/ScriptChunk.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/ScriptChunk.java @@ -145,7 +145,8 @@ public class ScriptChunk { } public boolean isScript() { - if(data == null || data.length == 0) { + //Do not attempt to parse long data byte arrays into scripts + if(data == null || data.length == 0 || data.length > 1000) { return false; } @@ -153,18 +154,20 @@ public class ScriptChunk { return false; } + Script script = new Script(data, false); try { - Script script = new Script(data); - //Flaky: Test if contains a non-zero opcode, otherwise not a script - for(ScriptChunk chunk : script.getChunks()) { - if(chunk.getOpcode() != OP_0) { - return true; - } - } - } catch(ProtocolException e) { + script.parse(); + } catch (ProtocolException e) { return false; } + //Flaky: Test if contains a non-zero opcode, otherwise not a script + for(ScriptChunk chunk : script.getChunks()) { + if(chunk.getOpcode() != OP_0) { + return true; + } + } + return false; }