ClojureScript

PersistHashMap's -conj implementation recurses infinitely if element to be conjed is not a vector.

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    Happens on cljsfiddle, among other environments.

Description

In commit b8681e8 the implementation is

ICollection
  (-conj [coll entry]
    (if (vector? entry)
      (-assoc coll (-nth entry 0) (-nth entry 1))
      (reduce -conj coll entry)))

Thus, e.g., (-conj {} "foo") results in an infinite recursion, and a stack overflow. This causes things like (merge {} "foo") to fail for the same reason.

Not sure what the purpose of the not-vector branch could be. I can't think of a situation where it would give a useful result. Maybe it could throw a more helpful error message.

Activity

Michał Marczyk made changes -
Field Original Value New Value
Assignee Michał Marczyk [ michalmarczyk ]
Michał Marczyk made changes -
Status Open [ 1 ] In Progress [ 3 ]
Michał Marczyk made changes -
Status In Progress [ 3 ] Open [ 1 ]
Michał Marczyk made changes -
David Nolen made changes -
Description In commit b8681e8 the implementation is

  ICollection
  (-conj [coll entry]
    (if (vector? entry)
      (-assoc coll (-nth entry 0) (-nth entry 1))
      (reduce -conj coll entry)))

Thus, e.g., (-conj {} "foo") results in an infinite recursion, and a stack overflow. This causes things like (merge {} "foo") to fail for the same reason.

Not sure what the purpose of the not-vector branch could be. I can't think of a situation where it would give a useful result. Maybe it could throw a more helpful error message.
In commit b8681e8 the implementation is

{code}
  ICollection
  (-conj [coll entry]
    (if (vector? entry)
      (-assoc coll (-nth entry 0) (-nth entry 1))
      (reduce -conj coll entry)))
{code}

Thus, e.g., {{(-conj {} "foo")}} results in an infinite recursion, and a stack overflow. This causes things like {{(merge {} "foo")}} to fail for the same reason.

Not sure what the purpose of the not-vector branch could be. I can't think of a situation where it would give a useful result. Maybe it could throw a more helpful error message.
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]
Herwig Hochleitner made changes -
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Completed [ 1 ]
Herwig Hochleitner made changes -
Michał Marczyk made changes -
David Nolen made changes -
Resolution Completed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: