Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetch a long base64 url will crash and nothing happens (close: #1574) #1575

Merged
merged 1 commit into from Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fetch/dataURL.js
Expand Up @@ -255,7 +255,7 @@ function percentDecode (input) {
}

// 3. Return output.
return Uint8Array.of(...output)
return Uint8Array.from(output)
}

// https://mimesniff.spec.whatwg.org/#parse-a-mime-type
Expand Down
18 changes: 17 additions & 1 deletion test/fetch/data-uri.js
Expand Up @@ -104,7 +104,7 @@ test('https://url.spec.whatwg.org/#string-percent-decode', (t) => {
const percentDecoded = stringPercentDecode(input)
const expected = [...input].map(c => c.charCodeAt(0))

t.same(percentDecoded, Uint8Array.of(...expected))
t.same(percentDecoded, Uint8Array.from(expected))
t.end()
})

Expand Down Expand Up @@ -211,5 +211,21 @@ test('processing.any.js', async (t) => {
}
}

// https://github.com/nodejs/undici/issues/1574
test('too long base64 url', async (t) => {
const inputStr = 'a'.repeat(1 << 20)
const base64 = Buffer.from(inputStr).toString('base64')
const dataURIPrefix = 'data:application/octet-stream;base64,'
const dataURL = dataURIPrefix + base64
try {
const res = await fetch(dataURL)
const buf = await res.arrayBuffer()
const outputStr = Buffer.from(buf).toString('ascii')
t.same(outputStr, inputStr)
} catch (e) {
t.fail(`failed to fetch ${dataURL}`)
}
})

t.end()
})