Skip to content

Bug report: Generate QR Code fails for PNG in Node API #2124

@GCHQDeveloper581

Description

@GCHQDeveloper581

Describe the bug
Generating a PNG QR code works fine using the Web UI, but applying the exact same recipe using the Node API fails.

To Reproduce
Using the URL https://gchq.github.io/CyberChef/#recipe=Generate_QR_Code('PNG',5,4,'Medium')To_Hex('Space',0)&input=SGVsbG8gd29ybGQh&ieol=CR&oeol=CR

produces a QR code and renders it in Hex. The start of the Hex produced is 89 50 4e 47 0d 0a 1a 0a which is a valid PNG header (and removing the To_Hex step will render a recognisable QR code)

The code

import chef from "cyberchef";

const recipe = [
    {
        "op": "Generate QR Code",
        "args": ["PNG", 5, 4, "Medium"]
    },
    {
        "op": "To Hex",
        "args": ["Space", 0]
    },
];

console.log(chef.bake("Hello world!", recipe));

Represents running the same recipe/data against the CyberChef node API.

Saving this as test.mjs and running "node test.mjs" produces output starting something like 2f 2a 2a 0a 20 2a 20 54 (actual output may vary). This is clearly not the start of a PNG.

Expected behaviour
Output of the test program above should match the output displayed in the Web UI

Desktop (if relevant, please complete the following information):

  • OS: Linux (Debian Bookworm)
  • Browser: N/A
  • CyberChef version: 10.19.4

Additional context
This is caused by incorrect manner of returning the generated PNG within src/core/lib/QRCode.mjs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions