Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dune subst crashes on large files (32-bit systems) #9538

Closed
emillon opened this issue Dec 19, 2023 · 4 comments · Fixed by #9811 or ocaml/opam-repository#25186
Closed

dune subst crashes on large files (32-bit systems) #9538

emillon opened this issue Dec 19, 2023 · 4 comments · Fixed by #9811 or ocaml/opam-repository#25186
Assignees
Labels

Comments

@emillon
Copy link
Collaborator

emillon commented Dec 19, 2023

dune subst crashes on 32-bit systems when a large file is present:

(true as of 3.12.1)

  Error: exception Invalid_argument("Bytes.create")
  Raised by primitive operation at Stdune__Io.Make.eagerly_input_string in file
    "otherlibs/stdune/src/io.ml", line 273, characters 14-30
  Called from Stdune__Io.Make.read_all.(fun) in file
    "otherlibs/stdune/src/io.ml", line 308, characters 16-40
  Called from Stdune__Exn.protectx in file "otherlibs/stdune/src/exn.ml", line
    10, characters 8-11
  Re-raised at Stdune__Exn.protectx in file "otherlibs/stdune/src/exn.ml", line
    16, characters 4-11
  Called from Dune__exe__Subst.subst_file in file "bin/subst.ml", line 113,
    characters 10-27
  Called from Stdlib__List.iter in file "list.ml", line 110, characters 12-15
  Called from Fiber__Core.O.(>>|).(fun) in file "vendor/fiber/src/core.ml",
    line 252, characters 36-41
  Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
    line 76, characters 8-11
  Re-raised at Stdune__Exn.raise_with_backtrace in file
    "otherlibs/stdune/src/exn.ml", line 38, characters 27-56
  Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
    line 76, characters 8-11
@emillon emillon added the bug label Dec 19, 2023
emillon added a commit that referenced this issue Dec 19, 2023
emillon added a commit that referenced this issue Dec 19, 2023
@moyodiallo
Copy link
Collaborator

dune subst crashes on 32-bit systems when a large file is present:

Can you give a size (example) ?

@emillon
Copy link
Collaborator Author

emillon commented Jan 16, 2024

There's a test case in #9539.
This is caused by the read_file call here:

https://github.com/ocaml/dune/blob/3.13.0/bin/subst.ml#L113

(the root cause is that the size of strings needs to fit in the header of an ocaml block)

In term of fix, personally I would consider it enough to catch the exception and log a warning. It's extremely unlikely that some users rely on substitution working on large files. If that's the case, we'll see another bug report.

@moyodiallo
Copy link
Collaborator

In term of fix, personally I would consider it enough to catch the exception and log a warning. It's extremely unlikely that some users rely on substitution working on large files. If that's the case, we'll see another bug report.

You're right we'll see another bug report cause 16MB is not that huge though. I think if we can fix it without a performance loss, it could be fine.

@emillon
Copy link
Collaborator Author

emillon commented Jan 16, 2024 via email

@emillon emillon self-assigned this Jan 22, 2024
emillon added a commit that referenced this issue Jan 23, 2024
emillon added a commit that referenced this issue Jan 23, 2024
emillon added a commit that referenced this issue Jan 30, 2024
Fixes #9538

This logs a warning for large files (>16MB on 32-bit systems).

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit that referenced this issue Jan 30, 2024
Fixes #9538

This logs a warning for large files (>16MB on 32-bit systems).

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit that referenced this issue Jan 30, 2024
Fixes #9538

This logs a warning for large files (>16MB on 32-bit systems).

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue Feb 5, 2024
emillon added a commit to emillon/dune that referenced this issue Feb 5, 2024
Fixes ocaml#9538

This logs a warning for large files (>16MB on 32-bit systems).

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue Feb 5, 2024
emillon added a commit to emillon/dune that referenced this issue Feb 5, 2024
Fixes ocaml#9538

This logs a warning for large files (>16MB on 32-bit systems).

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit that referenced this issue Feb 5, 2024
* test: add repro for #9538 (subst on 32-bit) (#9539)

Signed-off-by: Etienne Millon <[email protected]>

* refactor: detect large files in Io functions (#9828)

`Io.read_all` and related functions read the contents of a file in a
string, which has a size limit (`Sys.max_string_length`) and can be an
issue in 32-bit systems. This makes an explicit check and raises a
`Code_error` in these situations.

Signed-off-by: Etienne Millon <[email protected]>

* fix(subst): ignore large files (#9811)

Fixes #9538

This logs a warning for large files (>16MB on 32-bit systems).

Signed-off-by: Etienne Millon <[email protected]>

---------

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/opam-repository that referenced this issue Feb 5, 2024
CHANGES:

- Fix performance regression for incremental builds (ocaml/dune#9769, fixes ocaml/dune#9738,
  @rgrinberg)

- Fix `dune ocaml top-module` to correctly handle absolute paths. (ocaml/dune#8249, fixes
  ocaml/dune#7370, @Alizter)

- subst: ignore broken symlinks when looking at source files (ocaml/dune#9810, fixes
  ocaml/dune#9593, @emillon)

- subst: do not fail on 32-bit systems when large files are encountered. Just
  log a warning in this case. (ocaml/dune#9811, fixes ocaml/dune#9538, @emillon)

- boot: sort directory entries in readdir. This makes the dune binary
  reproducible in terms of filesystem order. (ocaml/dune#9861, fixes ocaml/dune#9794, @emillon)
nberth pushed a commit to nberth/opam-repository that referenced this issue Jun 18, 2024
CHANGES:

- Fix performance regression for incremental builds (ocaml/dune#9769, fixes ocaml/dune#9738,
  @rgrinberg)

- Fix `dune ocaml top-module` to correctly handle absolute paths. (ocaml/dune#8249, fixes
  ocaml/dune#7370, @Alizter)

- subst: ignore broken symlinks when looking at source files (ocaml/dune#9810, fixes
  ocaml/dune#9593, @emillon)

- subst: do not fail on 32-bit systems when large files are encountered. Just
  log a warning in this case. (ocaml/dune#9811, fixes ocaml/dune#9538, @emillon)

- boot: sort directory entries in readdir. This makes the dune binary
  reproducible in terms of filesystem order. (ocaml/dune#9861, fixes ocaml/dune#9794, @emillon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants