Skip to content

Commit 40af2c0

Browse files
authored
fix: fetch a long base64 url will crash and nothing happens (close: #1574) (#1575)
1 parent 2944587 commit 40af2c0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/fetch/dataURL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function percentDecode (input) {
255255
}
256256

257257
// 3. Return output.
258-
return Uint8Array.of(...output)
258+
return Uint8Array.from(output)
259259
}
260260

261261
// https://mimesniff.spec.whatwg.org/#parse-a-mime-type

test/fetch/data-uri.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test('https://url.spec.whatwg.org/#string-percent-decode', (t) => {
104104
const percentDecoded = stringPercentDecode(input)
105105
const expected = [...input].map(c => c.charCodeAt(0))
106106

107-
t.same(percentDecoded, Uint8Array.of(...expected))
107+
t.same(percentDecoded, Uint8Array.from(expected))
108108
t.end()
109109
})
110110

@@ -211,5 +211,21 @@ test('processing.any.js', async (t) => {
211211
}
212212
}
213213

214+
// https://github.com/nodejs/undici/issues/1574
215+
test('too long base64 url', async (t) => {
216+
const inputStr = 'a'.repeat(1 << 20)
217+
const base64 = Buffer.from(inputStr).toString('base64')
218+
const dataURIPrefix = 'data:application/octet-stream;base64,'
219+
const dataURL = dataURIPrefix + base64
220+
try {
221+
const res = await fetch(dataURL)
222+
const buf = await res.arrayBuffer()
223+
const outputStr = Buffer.from(buf).toString('ascii')
224+
t.same(outputStr, inputStr)
225+
} catch (e) {
226+
t.fail(`failed to fetch ${dataURL}`)
227+
}
228+
})
229+
214230
t.end()
215231
})

0 commit comments

Comments
 (0)