Skip to content

Commit d0f3bfd

Browse files
committed
FIX: prevent infinite loop when resolving the size of virtual files
related to: Oldes/Rebol-issues#2303
1 parent 055c092 commit d0f3bfd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/os/posix/dev-file.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,15 @@ static int Get_File_Info(REBREQ *file)
434434
}
435435

436436
// Resolves real size of virtual files (like /proc/cpuinfo)
437+
// NOTE: always use read/part with files like /dev/urandom
437438
static size_t get_virtual_file_size(const char *filepath) {
438439
#define BUFFER_SIZE 4096
440+
#define READ_LIMIT 0x80000000 // Rebol has limit 2GB for series
439441
char buffer[BUFFER_SIZE];
440442
size_t size = 0;
441443
int file = open(filepath, O_RDONLY, S_IREAD);
442444
if (file) {
443-
while (1) {
445+
while (size < READ_LIMIT) {
444446
size_t bytesRead = read(file, buffer, BUFFER_SIZE);
445447
if (bytesRead == 0) break;
446448
size += bytesRead;

0 commit comments

Comments
 (0)