Skip to content

Commit

Permalink
fix(TextDecoder): Do not reuse text decoders to avoid spilling data f…
Browse files Browse the repository at this point in the history
…rom one instance to another
  • Loading branch information
andris9 committed Jan 24, 2025
1 parent db3e835 commit 8b1013e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
21 changes: 2 additions & 19 deletions src/decode-strings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const textEncoder = new TextEncoder();

const decoders = new Map();

const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

// Use a lookup table to find the index.
Expand Down Expand Up @@ -46,23 +44,7 @@ export function decodeBase64(base64) {

export function getDecoder(charset) {
charset = charset || 'utf8';
if (decoders.has(charset)) {
return decoders.get(charset);
}
let decoder;
try {
decoder = new TextDecoder(charset);
} catch (err) {
if (charset === 'utf8') {
// is this even possible?
throw err;
}
// use default
return getDecoder();
}

decoders.set(charset, decoder);
return decoder;
return new TextDecoder(charset);
}

/**
Expand Down Expand Up @@ -157,6 +139,7 @@ export function decodeWord(charset, encoding, str) {
export function decodeWords(str) {
let joinString = true;
let done = false;

while (!done) {
let result = (str || '')
.toString()
Expand Down
1 change: 0 additions & 1 deletion src/mime-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default class MimeNode {
this.state = 'header';

this.headerLines = [];
this.decoders = new Map();

this.contentType = {
value: 'text/plain',
Expand Down

0 comments on commit 8b1013e

Please sign in to comment.