From 6b454451d7d8d415c40dd14dcc8a608cbc21794b Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Fri, 11 Feb 2022 17:27:33 -0600 Subject: [PATCH] Fix the `_from_string` instruction This replaces the dangerous use of `read-string`with `parseInt` and `parseFloat`, and returns `ignore-instruction` if an exception is thrown when trying to do the parsing. Hopefully this will fix the stack overflow problems with the PSB2 Middle Character and Twitter problems. --- src/propeller/push/instructions/numeric.cljc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/propeller/push/instructions/numeric.cljc b/src/propeller/push/instructions/numeric.cljc index b9cbf1f..455dad4 100755 --- a/src/propeller/push/instructions/numeric.cljc +++ b/src/propeller/push/instructions/numeric.cljc @@ -121,9 +121,13 @@ :name "_from_string"} (fn [stack state] (make-instruction state - #(try ((if (= stack :integer) int float) (read-string %)) - #?(:clj (catch Exception e) - :cljs (catch js/Error. e))) + #(try (if (= stack :integer) + #?(:clj (Integer/parseInt %) + :cljs (js/parseInt %)) + #?(:clj (Float/parseFloat %) + :cljs (js/parseFloat %))) + #?(:clj (catch Exception e :ignore-instruction) + :cljs (catch js/Error e :ignore-instruction))) [:string] stack)))