gchq / gchq/CyberChef

Bug report: decoding hybrid hex and unicode escaped string, extra null character is parsed ?

Open
#1,039 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
35.8k
Forks
4.1k
Avg merge
2d 26m
Merged PRs (30d)
33

Description

**Describe the bug**
Trying to unescape mixed hex and unicode escaped input such as `\x41\u0042`, an extra null `00` is parsed unexpectedly at the location of the unicode escape

Basically the problem I'm trying to solve is: how to correctly decode mixed unicode and hex escaped string ?

**To Reproduce**
Steps to reproduce the behaviour or a link to the recipe / input used to cause the bug:

Mixed unicode and hex escaped string input `\x41\u0042`
1. https://gchq.github.io/CyberChef/#recipe=From_Hex('%5C%5Cx')Unescape_Unicode_Characters('%5C%5Cu')To_Hex('Space',0)&input=XHg0MVx1MDA0Mg

**Expected behaviour**
Output should be `41 00 42` (`A.B`)

The actual output appears to contain an extra null character `41 00 00 42`
This would make sense with padding, but [adding another hex character](https://gchq.github.io/CyberChef/#recipe=From_Hex('%5C%5Cx')Unescape_Unicode_Characters('%5C%5Cu')To_Hex('Space',0)&input=XHg0MVx1MDA0Mlx4NDM) at the beginning or end of the sequence does not add additional padding

So it seems either the padding is inconsistent, or it is appending an extra null character when it shouldn't be.

Reversing the order of the hex and unicode escapes produces less correct results. https://gchq.github.io/CyberChef/#recipe=Unescape_Unicode_Characters('%5C%5Cu')From_Hex('%5C%5Cx')To_Hex('Space',0)&input=XHg0MVx1MDA0Mg

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (if relevant, please complete the following information):**
- Browser: Firefox 76.0.1
- CyberChef version: 9.20.3

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.