mirror of
https://github.com/penpot/penpot.git
synced 2026-09-10 14:09:17 +00:00
🐛 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.
This commit is contained in:
parent
a19b3c8d62
commit
a4becb5d1f
@ -467,25 +467,26 @@
|
|||||||
Raises :validation :max-file-size-reached when the limit is exceeded."
|
Raises :validation :max-file-size-reached when the limit is exceeded."
|
||||||
^InputStream
|
^InputStream
|
||||||
[^InputStream input ^long max-size]
|
[^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]
|
(proxy [FilterInputStream] [input]
|
||||||
(read
|
(read
|
||||||
([]
|
([]
|
||||||
(let [b (.read input)]
|
(let [b (.read input)]
|
||||||
(when (pos? b)
|
(when (pos? b) (on-read 1))
|
||||||
(when (> (swap! counter inc) max-size)
|
|
||||||
(ex/raise :type :validation
|
|
||||||
:code :max-file-size-reached
|
|
||||||
:hint (str "stream exceeded max size: " max-size))))
|
|
||||||
b))
|
b))
|
||||||
([buf off len]
|
([^bytes buf]
|
||||||
(let [n (.read input buf off len)]
|
(on-read (.read input buf 0 (alength buf))))
|
||||||
(when (pos? n)
|
([^bytes buf off]
|
||||||
(when (> (swap! counter + (long n)) max-size)
|
(on-read (.read input buf (int off) (- (alength buf) (int off)))))
|
||||||
(ex/raise :type :validation
|
([^bytes buf off len]
|
||||||
:code :max-file-size-reached
|
(on-read (.read input buf (int off) (int len))))))))
|
||||||
:hint (str "stream exceeded max size: " max-size))))
|
|
||||||
n))))))
|
|
||||||
|
|
||||||
(defn- zip-entry-reader
|
(defn- zip-entry-reader
|
||||||
[^ZipFile input ^ZipEntry entry]
|
[^ZipFile input ^ZipEntry entry]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user