You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 5004 Reporter: myst Status: closed (set by @xavierleroy on 2010-03-28T08:17:40Z) Resolution: fixed Priority: normal Severity: minor Version: 3.11.1 Fixed in version: 3.12.0+dev Category: ~DO NOT USE (was: OCaml general)
Bug description
I am trying to read whole file by doing:
let read_file_bin name =
let ic = open_in_bin name in
let b = Buffer.create 1024 in
(try Buffer.add_channel b ic max_int with _ -> ()); (* <-- HERE *)
close_in ic;
Array.init (Buffer.length b) (fun i -> int_of_char (Buffer.nth b i))
but it hangs on the line marked.
The problem is max_int and the fact that Buffer.add_channel and Buffer.resize do not check for this possibility:
let add_channel b ic len =
if b.position + len > b.length then resize b len;
really_input ic b.buffer b.position len;
b.position <- b.position + len
Something like the following would be better:
let add_channel b ic len =
if len < 0 || len > Sys.max_string_length then
invalid_arg "Buffer.add_channel";
...
The text was updated successfully, but these errors were encountered:
Original bug ID: 5004
Reporter: myst
Status: closed (set by @xavierleroy on 2010-03-28T08:17:40Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.1
Fixed in version: 3.12.0+dev
Category: ~DO NOT USE (was: OCaml general)
Bug description
I am trying to read whole file by doing:
let read_file_bin name =
let ic = open_in_bin name in
let b = Buffer.create 1024 in
(try Buffer.add_channel b ic max_int with _ -> ()); (* <-- HERE *)
close_in ic;
Array.init (Buffer.length b) (fun i -> int_of_char (Buffer.nth b i))
but it hangs on the line marked.
The problem is max_int and the fact that Buffer.add_channel and Buffer.resize do not check for this possibility:
let add_channel b ic len =
if b.position + len > b.length then resize b len;
really_input ic b.buffer b.position len;
b.position <- b.position + len
Something like the following would be better:
let add_channel b ic len =
if len < 0 || len > Sys.max_string_length then
invalid_arg "Buffer.add_channel";
...
The text was updated successfully, but these errors were encountered: