Skip to content

Commit

Permalink
FIX: prevent infinite loop when resolving the size of virtual files
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed May 28, 2024
1 parent 055c092 commit d0f3bfd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/os/posix/dev-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,15 @@ static int Get_File_Info(REBREQ *file)
}

// Resolves real size of virtual files (like /proc/cpuinfo)
// NOTE: always use read/part with files like /dev/urandom
static size_t get_virtual_file_size(const char *filepath) {
#define BUFFER_SIZE 4096
#define READ_LIMIT 0x80000000 // Rebol has limit 2GB for series
char buffer[BUFFER_SIZE];
size_t size = 0;
int file = open(filepath, O_RDONLY, S_IREAD);
if (file) {
while (1) {
while (size < READ_LIMIT) {
size_t bytesRead = read(file, buffer, BUFFER_SIZE);
if (bytesRead == 0) break;
size += bytesRead;
Expand Down

0 comments on commit d0f3bfd

Please sign in to comment.