Bug report: Generate Image fails in Node API when followed by another operation in the recipe.
- Dominant language
- JavaScript
- Stars
- 35.8k
- Forks
- 4.1k
- Avg merge
- 2d 26m
- Merged PRs (30d)
- 33
Description
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 ()
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)
Contributor guide
Research direction
Reproduce the recipe with the Node API, then trace NodeRecipe.execute through prepareOp and ensureIsDish in src/node/api.mjs, followed by Dish.typeEnum in src/core/Dish.mjs and NodeDish in src/node/NodeDish.mjs. Compare the Node API result with the Web UI output and check whether Convert Image Format shows the same failure. Done means the supplied Generate Image followed by To Hex recipe produces matching output without a DishError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100