Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

crypto: getDecoder throws "AssertionError: Cannot change encoding" when encoding is "utf-8". #5655

@dtinth

Description

@dtinth

Hello,

In lib/crypto.js, the assert in getDecoder function is inadequate:

assert(decoder.encoding === encoding, 'Cannot change encoding');

When encoding is "utf-8", it gets passed to new StringDecoder(encoding). However, the StringDecoder interprets "utf-8" as "utf8", and sets the encoding property as "utf8", thus making the assertion fail.

An example code that would make it throw an AssertionError:

require('crypto').createDecipher('bf','').update('','hex','utf-8')

If I use "utf8" instead of "utf-8", it won't throw an AssertionError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions