Skip to content

Bug report: Generate Image fails in Node API when followed by another operation in the recipe. #2184

@GCHQDeveloper581

Description

@GCHQDeveloper581

Describe the bug
Generating an image 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_Image('Greyscale',1,4)To_Hex('Space',0)&input=SGVsbG8gd29ybGQh&ieol=CR&oeol=CR

generates an image 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 image)

The code

import chef from "cyberchef";

const recipe = [
    {
        "op": "Generate Image",
        "args": ["Greyscale", 1, 4]
    },
    {
        "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 concluding with an error:

DishError: Invalid data type string. No matching enum.
    at Dish.typeEnum (file:///workspaces/CyberChef/src/core/Dish.mjs:88:23)
    at new Dish (file:///workspaces/CyberChef/src/core/Dish.mjs:51:39)
    at new NodeDish (file:///workspaces/CyberChef/src/node/NodeDish.mjs:31:9)
    at ensureIsDish (file:///workspaces/CyberChef/src/node/api.mjs:108:16)
    at prepareOp (file:///workspaces/CyberChef/src/node/api.mjs:121:18)
    at Object.wrapped [as op] (file:///workspaces/CyberChef/src/node/api.mjs:231:57)
    at file:///workspaces/CyberChef/src/node/NodeRecipe.mjs:96:29
    at Array.reduce (<anonymous>)
    at NodeRecipe.execute (file:///workspaces/CyberChef/src/node/NodeRecipe.mjs:92:28)
    at Object.bake (file:///workspaces/CyberChef/src/node/api.mjs:330:19) {
  type: 'DishError'
}

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.21.0 (specifically master@cc2c6d20)
Node version: v18.20.8

Additional context:
Adding debugging to Dish.typeEnum shows the traceback above is triggered by the type name presented being "Promise" which is not an expected type.

However other junk output from the program above suggests this may not be the only issue present.

Some other Image functions look to have similar problems (specifically Convert Image Format)

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