Skip to content

Commit 53da078

Browse files
committed
buffer: fix out of range for toString
nodejs/node#54553
1 parent c393f73 commit 53da078

1 file changed

Lines changed: 76 additions & 23 deletions

File tree

patches/node/fix_crypto_tests_to_run_with_bssl.patch

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,53 @@ This should be upstreamed in some form, though it may need to be tweaked
1010
before it's acceptable to upstream, as this patch comments out a couple
1111
of tests that upstream probably cares about.
1212

13+
diff --git a/test/common/index.js b/test/common/index.js
14+
index 172cdb6b049824539a9850789e0e7c5baf613367..43191263d761c95805f74ca0963e2ac731a835ca 100644
15+
--- a/test/common/index.js
16+
+++ b/test/common/index.js
17+
@@ -65,6 +65,8 @@ const opensslVersionNumber = (major = 0, minor = 0, patch = 0) => {
18+
return (major << 28) | (minor << 20) | (patch << 4);
19+
};
20+
21+
+const openSSLIsBoringSSL = process.versions.openssl === '0.0.0';
22+
+
23+
let OPENSSL_VERSION_NUMBER;
24+
const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
25+
if (!hasCrypto) return false;
26+
@@ -754,6 +756,8 @@ function skipIfInspectorDisabled() {
27+
}
28+
}
29+
30+
+
31+
+
32+
function skipIf32Bits() {
33+
if (bits < 64) {
34+
skip('The tested feature is not available in 32bit builds');
35+
@@ -996,6 +1000,7 @@ const common = {
36+
mustNotMutateObjectDeep,
37+
mustSucceed,
38+
nodeProcessAborted,
39+
+ openSSLIsBoringSSL,
40+
PIPE,
41+
parseTestFlags,
42+
platformTimeout,
43+
diff --git a/test/parallel/test-buffer-tostring-range.js b/test/parallel/test-buffer-tostring-range.js
44+
index d033cd204b3200cdd736b581abe027d6e46e4ff3..4c1d03774717cb4dbbdf1e3a06ef34ac4e533738 100644
45+
--- a/test/parallel/test-buffer-tostring-range.js
46+
+++ b/test/parallel/test-buffer-tostring-range.js
47+
@@ -102,7 +102,8 @@ assert.throws(() => {
48+
// Must not throw when start and end are within kMaxLength
49+
// Cannot test on 32bit machine as we are testing the case
50+
// when start and end are above the threshold
51+
-common.skipIf32Bits();
52+
-const threshold = 0xFFFFFFFF;
53+
-const largeBuffer = Buffer.alloc(threshold + 20);
54+
-largeBuffer.toString('utf8', threshold, threshold + 20);
55+
+if (!common.openSSLIsBoringSSL) {
56+
+ const threshold = 0xFFFFFFFF;
57+
+ const largeBuffer = Buffer.alloc(threshold + 20);
58+
+ largeBuffer.toString('utf8', threshold, threshold + 20);
59+
+}
1360
diff --git a/test/parallel/test-crypto-async-sign-verify.js b/test/parallel/test-crypto-async-sign-verify.js
1461
index 4e3c32fdcd23fbe3e74bd5e624b739d224689f33..19d65aae7fa8ec9f9b907733ead17a208ed47909 100644
1562
--- a/test/parallel/test-crypto-async-sign-verify.js
@@ -686,56 +733,62 @@ index b06f2fa2c53ea72f9a66f0d002dd9281d0259a0f..864fffeebfad75d95416fd47efdea7f2
686733

687734
const server = https.createServer(opts, (req, res) => {
688735
diff --git a/test/parallel/test-webcrypto-derivebits.js b/test/parallel/test-webcrypto-derivebits.js
689-
index eb09bc24f0cb8244b05987e3a7c1d203360d3a38..da891fffa29d5666d91e4445e54c43e3688b870a 100644
736+
index eb09bc24f0cb8244b05987e3a7c1d203360d3a38..011990db171faa708c5211f6ab9ae1ac0e0ab90e 100644
690737
--- a/test/parallel/test-webcrypto-derivebits.js
691738
+++ b/test/parallel/test-webcrypto-derivebits.js
692-
@@ -101,6 +101,7 @@ const { subtle } = globalThis.crypto;
739+
@@ -101,8 +101,9 @@ const { subtle } = globalThis.crypto;
693740
tests.then(common.mustCall());
694741
}
695742

696-
+/*
743+
+
697744
// Test X25519 and X448 bit derivation
698-
{
745+
-{
746+
+if (!common.openSSLIsBoringSSL) {
699747
async function test(name) {
748+
const [alice, bob] = await Promise.all([
749+
subtle.generateKey({ name }, true, ['deriveBits']),
700750
@@ -126,3 +127,4 @@ const { subtle } = globalThis.crypto;
701751
test('X25519').then(common.mustCall());
702752
test('X448').then(common.mustCall());
703753
}
704-
+*/
754+
+
705755
diff --git a/test/parallel/test-webcrypto-derivekey.js b/test/parallel/test-webcrypto-derivekey.js
706-
index 558d37d90d5796b30101d1b512c9df3e7661d0db..c18f9670b10cb84c6902391f20e0ff75729cc960 100644
756+
index 558d37d90d5796b30101d1b512c9df3e7661d0db..f42bf8f4be0b439dd7e7c8d0f6f8a41e01588870 100644
707757
--- a/test/parallel/test-webcrypto-derivekey.js
708758
+++ b/test/parallel/test-webcrypto-derivekey.js
709-
@@ -175,6 +175,7 @@ const { KeyObject } = require('crypto');
710-
})().then(common.mustCall());
759+
@@ -176,7 +176,7 @@ const { KeyObject } = require('crypto');
711760
}
712761

713-
+/*
714762
// Test X25519 and X448 key derivation
715-
{
763+
-{
764+
+if (!common.openSSLIsBoringSSL) {
716765
async function test(name) {
717-
@@ -209,3 +210,4 @@ const { KeyObject } = require('crypto');
718-
test('X25519').then(common.mustCall());
719-
test('X448').then(common.mustCall());
720-
}
721-
+*/
766+
const [alice, bob] = await Promise.all([
767+
subtle.generateKey({ name }, true, ['deriveKey']),
722768
diff --git a/test/parallel/test-webcrypto-sign-verify.js b/test/parallel/test-webcrypto-sign-verify.js
723-
index de736102bdcb71a5560c95f7041537f25026aed4..638fdf0d798f3309528c63f0f8598f3df5528339 100644
769+
index de736102bdcb71a5560c95f7041537f25026aed4..12d7fa39446c196bdf1479dbe74c9ee8ab02f949 100644
724770
--- a/test/parallel/test-webcrypto-sign-verify.js
725771
+++ b/test/parallel/test-webcrypto-sign-verify.js
726-
@@ -105,6 +105,7 @@ const { subtle } = globalThis.crypto;
772+
@@ -105,8 +105,9 @@ const { subtle } = globalThis.crypto;
727773
test('hello world').then(common.mustCall());
728774
}
729775

730-
+/*
776+
+
731777
// Test Sign/Verify Ed25519
732-
{
778+
-{
779+
+if (!common.openSSLIsBoringSSL) {
733780
async function test(data) {
734-
@@ -144,3 +145,4 @@ const { subtle } = globalThis.crypto;
735-
736-
test('hello world').then(common.mustCall());
781+
const ec = new TextEncoder();
782+
const { publicKey, privateKey } = await subtle.generateKey({
783+
@@ -126,7 +127,7 @@ const { subtle } = globalThis.crypto;
737784
}
738-
+*/
785+
786+
// Test Sign/Verify Ed448
787+
-{
788+
+if (!common.openSSLIsBoringSSL) {
789+
async function test(data) {
790+
const ec = new TextEncoder();
791+
const { publicKey, privateKey } = await subtle.generateKey({
739792
diff --git a/test/parallel/test-webcrypto-wrap-unwrap.js b/test/parallel/test-webcrypto-wrap-unwrap.js
740793
index d1ca571af4be713082d32093bfb8a65f2aef9800..57b8df2ce18df58ff54b2d828af67e3c2e082fe0 100644
741794
--- a/test/parallel/test-webcrypto-wrap-unwrap.js

0 commit comments

Comments
 (0)