Skip to content

Commit c5efbdd

Browse files
committed
update lib_src_switch_buffer_kmaxlength_to_size_t.patch
1 parent 2c1d6bf commit c5efbdd

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

patches/node/lib_src_switch_buffer_kmaxlength_to_size_t.patch

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Ben Noordhuis <info@bnoordhuis.nl>
33
Date: Sat, 18 Jan 2020 10:55:31 +0100
44
Subject: lib,src: switch Buffer::kMaxLength to size_t
5-
MIME-Version: 1.0
6-
Content-Type: text/plain; charset=UTF-8
7-
Content-Transfer-Encoding: 8bit
85

96
Change the type of `Buffer::kMaxLength` to size_t because upcoming
107
changes in V8 will allow typed arrays > 2 GB on 64 bits platforms.
@@ -114,6 +111,39 @@ index d653724474f314cd1c6bebe0a2d9285439d54928..98335fdc1027409a2f17ae50fba378f5
114111
throw new ERR_FS_FILE_TOO_LARGE(size);
115112

116113
const chunks = [];
114+
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js
115+
index 6f096336f20e10727b6328af9f0130b37de74050..ff26568bd95e0c966b7f3a7c63d3f594b411fbab 100644
116+
--- a/lib/internal/fs/utils.js
117+
+++ b/lib/internal/fs/utils.js
118+
@@ -12,7 +12,7 @@ const {
119+
Symbol,
120+
} = primordials;
121+
122+
-const { Buffer, kMaxLength } = require('buffer');
123+
+const { Buffer } = require('buffer');
124+
const {
125+
codes: {
126+
ERR_FS_INVALID_SYMLINK_TYPE,
127+
@@ -72,6 +72,10 @@ const {
128+
129+
const isWindows = process.platform === 'win32';
130+
131+
+// Most platforms don't allow reads or writes >= 2 GB.
132+
+// See https://github.com/libuv/libuv/pull/1501.
133+
+const kIoMaxLength = 2 ** 31 - 1;
134+
+
135+
let fs;
136+
function lazyLoadFs() {
137+
if (!fs) {
138+
@@ -525,7 +529,7 @@ const validateOffsetLengthWrite = hideStackFrames(
139+
throw new ERR_OUT_OF_RANGE('offset', `<= ${byteLength}`, offset);
140+
}
141+
142+
- const max = byteLength > kMaxLength ? kMaxLength : byteLength;
143+
+ const max = byteLength > kIoMaxLength ? kIoMaxLength : byteLength;
144+
if (length > max - offset) {
145+
throw new ERR_OUT_OF_RANGE('length', `<= ${max - offset}`, length);
146+
}
117147
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
118148
index 59baa45413d500272d0e293ab06bfe4d24e5e0cb..4d1951b740240bff231b7f4c855beb5b73d076af 100644
119149
--- a/src/node_buffer.cc

0 commit comments

Comments
 (0)