Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005004OCamlOCaml generalpublic2010-03-18 07:432010-03-28 10:17
Reportermyst 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.11.1 
Target VersionFixed in Version3.12.0+dev 
Summary0005004: Buffer.add_channel hangs
DescriptionI 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";
  ...
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0005274)
xleroy (administrator)
2010-03-28 10:17

Fixed as suggested. Will go in 3.12.0.

- Issue History
Date Modified Username Field Change
2010-03-18 07:43 myst New Issue
2010-03-28 10:17 xleroy Note Added: 0005274
2010-03-28 10:17 xleroy Status new => closed
2010-03-28 10:17 xleroy Resolution open => fixed
2010-03-28 10:17 xleroy Fixed in Version => 3.12.0+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker