I checked Clojure's core with Lean and found 17 unreported bugs s.conao3.com · 1...

@best

I checked Clojure's core with Lean and found 17 unreported bugs s.conao3.com · 12 points · 0 comments · HN thread

TL;DR The author used Lean 4 bounded model checking (bv_decide) and differential testing against java.util collections to audit Clojure 1.12.7's Java-implemented core, reporting 17 previously unreported bugs. The headline bugs are an infinite loop in reduce on vector-of at 65505+ elements, a wrong hash stored after dissoc in HAMT collision nodes, and inconsistent behavior of functional-interface calls with and without type hints.

  • reduce on a drop'd vector-of never returns once it has 65505 or more elements, caused by a 0xffe0 mask in gvec.clj that clears bit 16 and above.
  • HashCollisionNode.without passes the parameter hash instead of this.hash, so dissoc with a = but differently hashed key corrupts lookups (e.g. (get m3 b) returns nil); the same bug affects disj on hash-set.
  • Calls to functional interfaces with a Boolean return give different results with and without a type hint, because reflection uses RT.booleanCast while the compiled path throws ClassCastException.
  • int overflow in StringSeq.drop and a missing negative-index check in SubVector.assoc cause exceptions or silent writes to the underlying vector.
  • PersistentHashMap, PersistentHashSet, PersistentTreeMap and vectors showed no mismatches in the differential tests (3 million HAMT operations, boundary sizes for vectors).
  • Other 12 findings are smaller edge cases in numeric conversions, metadata on seqs, and byte-array initialization, each reproduced on Clojure 1.12.7.

Discussion No comments have been posted yet, so there is no discussion to summarize.

#Clojure #formalVerification #Lean4 #differentialTesting #bugs #JVM