Skip to content

Conversation

@gguyver
Copy link

@gguyver gguyver commented Nov 24, 2025

Fixes #1590

@tinarozsos and I have worked on this. read_file() and read_file_raw() both cause a segmentation fault (crashing R) when reading an empty raw vector. This issue does not arise when using other types of empty vector because those are caught and errored by other aspects of the function before reaching the relevant code. Nor does the behaviour arise when using a non-empty raw vector (e.g. raw(1)). There are potentially two issues here: 1) the code reaches a point where it attempts to access unowned memory; 2) the C code doesn't catch that the memory is unowned and still tries to access it. We address the first issue.

Because all the affected functions use datasource() to dispatch to the relevant function, we add a simple check for a vector size greater than 0, also providing an informative error message. We also add a couple of tests for this behaviour.

We hope this is helpful :).

gguyver and others added 3 commits November 24, 2025 20:28
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readr::read_file() and readr::read_file_raw() crash R session when given an empty raw vector

1 participant