From a4becb5d1f436198ff93ba05356945b7b34de72f Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 2 Sep 2026 10:28:16 +0200 Subject: [PATCH] :bug: Fix size-limiting-stream read arity on v3 binfile import (#11468) The FilterInputStream proxy only implemented read() and read(byte[], int, int). Buffered reads call read(byte[]) (and read(byte[], int) via Clojure interop), causing ArityException while hashing storage objects and breaking v3 imports. Implement all read overloads and extract shared byte-count logic. --- backend/src/app/binfile/v3.clj | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/backend/src/app/binfile/v3.clj b/backend/src/app/binfile/v3.clj index 01e735d364..9d4801dd4a 100644 --- a/backend/src/app/binfile/v3.clj +++ b/backend/src/app/binfile/v3.clj @@ -467,25 +467,26 @@ Raises :validation :max-file-size-reached when the limit is exceeded." ^InputStream [^InputStream input ^long max-size] - (let [counter (atom 0)] + (let [counter (atom 0) + on-read (fn [n] + (when (pos? n) + (when (> (swap! counter + (long n)) max-size) + (ex/raise :type :validation + :code :max-file-size-reached + :hint (str "stream exceeded max size: " max-size)))) + n)] (proxy [FilterInputStream] [input] (read ([] (let [b (.read input)] - (when (pos? b) - (when (> (swap! counter inc) max-size) - (ex/raise :type :validation - :code :max-file-size-reached - :hint (str "stream exceeded max size: " max-size)))) + (when (pos? b) (on-read 1)) b)) - ([buf off len] - (let [n (.read input buf off len)] - (when (pos? n) - (when (> (swap! counter + (long n)) max-size) - (ex/raise :type :validation - :code :max-file-size-reached - :hint (str "stream exceeded max size: " max-size)))) - n)))))) + ([^bytes buf] + (on-read (.read input buf 0 (alength buf)))) + ([^bytes buf off] + (on-read (.read input buf (int off) (- (alength buf) (int off))))) + ([^bytes buf off len] + (on-read (.read input buf (int off) (int len)))))))) (defn- zip-entry-reader [^ZipFile input ^ZipEntry entry]