Clojure

java.io/do-copy can garble multibyte characters

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.3
  • Fix Version/s: Release 1.4
  • Component/s: None
  • Labels:
  • Environment:
    all
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

See comments in fix:

(defmethod do-copy [InputStream Writer] [#^InputStream input #^Writer output opts]
;; WRONG! if the buffer boundry falls in the middle of a multibyte character, we will get garbled results.
#_
(let [#^"[B" buffer (make-array Byte/TYPE (buffer-size opts))]
(loop []
(let [size (.read input buffer)]
(when (pos? size)
(let [chars (.toCharArray (String. buffer 0 size (encoding opts)))]
(do (.write output chars)
(recur)))))))
;; here we decode the characters before stuffing them into the buffer
(let [#^"[C" buffer (make-array Character/TYPE (buffer-size opts))
in (InputStreamReader. input (encoding opts))]
(loop []
(let [size (.read in buffer 0 (alength buffer))]
(if (pos? size)
(do (.write output buffer 0 size)
(recur)))))))

  1. CLJ-886-fix2.patch
    09/Feb/12 8:13 PM
    7 kB
    Andy Fingerhut
  2. clj-886.diff
    05/Dec/11 11:23 AM
    2 kB
    Jeff Palmucci

Activity

Hide
Jeff Palmucci added a comment -

Make patch file per http://clojure.org/patches. Also sent in my CA.

Show
Jeff Palmucci added a comment - Make patch file per http://clojure.org/patches. Also sent in my CA.
Hide
Jeff Palmucci added a comment -

Any reason why this hasn't been applied yet? It's a pretty serious error. Just wondering if I've submitted anything incorrectly. Thanks.

Show
Jeff Palmucci added a comment - Any reason why this hasn't been applied yet? It's a pretty serious error. Just wondering if I've submitted anything incorrectly. Thanks.
Hide
Andy Fingerhut added a comment -

CLJ-886-fix2.patch includes Jeff Palmucci's fix, plus another one found while enhancing clojure.java.io's unit tests to fail with the original code. Tested on Mac OS X 10.6.8 with java 1.6.0_29 and Ubuntu Linux 11.04 with JVM 1.7.0_02.

Show
Andy Fingerhut added a comment - CLJ-886-fix2.patch includes Jeff Palmucci's fix, plus another one found while enhancing clojure.java.io's unit tests to fail with the original code. Tested on Mac OS X 10.6.8 with java 1.6.0_29 and Ubuntu Linux 11.04 with JVM 1.7.0_02.
Hide
Jeff Palmucci added a comment -

Andy's fix is good. Please use the fix2 patch instead of the original.

Show
Jeff Palmucci added a comment - Andy's fix is good. Please use the fix2 patch instead of the original.
Hide
Stuart Sierra added a comment -

Screened. Patch applies successfully and the tests seem to be complete.

Show
Stuart Sierra added a comment - Screened. Patch applies successfully and the tests seem to be complete.

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: