Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON's syscalls can't deal with NULL values #1112

Closed
shargon opened this issue Sep 24, 2019 · 6 comments · Fixed by #1081
Closed

JSON's syscalls can't deal with NULL values #1112

shargon opened this issue Sep 24, 2019 · 6 comments · Fixed by #1081

Comments

@shargon
Copy link
Member

shargon commented Sep 24, 2019

Describe the bug

In Red4sec we are preparing a fuzzing process for different neo areas. We find a issue with null values.

To Reproduce

using (var script = new ScriptBuilder())
            using (var engine = new ApplicationEngine(TriggerType.Application, null, null, 0, true))
            {
                script.EmitPush("{\"a\":1,\"b\":null}");
                script.EmitSysCall(InteropService.Neo_Json_Deserialize);
                script.EmitSysCall(InteropService.Neo_Json_Serialize);
                engine.LoadScript(script.ToArray());
                engine.Execute();
                var ret = engine.ResultStack.Peek().GetString();
            }

Expected behavior

The expected result should be {"a":1,"b":null}

Screenshots
image

Source Reference:

default: throw new FormatException();

Platform:

  • Version [e.g. neo 3x]

Additional context
In addition, it should be possible to reverse a null value, to a null json value, and the VM will treat null values ​​as a byte [0], how will it be possible to distinguish between an empty byte array and a null?

@erikzhang
Copy link
Member

Should we add new opcodes PUSHNULL and ISNULL?

@shargon
Copy link
Member Author

shargon commented Sep 25, 2019

I think that we can use ByteArray, but a special one, we have a null item.

https://github.com/neo-project/neo-vm/blob/6676592b667cd39c26f46af41d7484cd054e4da1/src/neo-vm/StackItem.cs#L13

Maybe we can check with ReferenceEqual on PUSHNULL and ISNULL?

@erikzhang
Copy link
Member

How to distinguish between null and byte[0]?

@shargon
Copy link
Member Author

shargon commented Sep 25, 2019

var item=stack.Pop();
if (Object.ReferenceEquals(item ,StackItem.Null)

@erikzhang
Copy link
Member

erikzhang commented Sep 26, 2019

Please check neo-project/neo-vm#208

@igormcoelho
Copy link
Contributor

igormcoelho commented Sep 26, 2019

How to distinguish between null and byte[0]?

new ByteArray(null) could have a constructor that receives null and indicates this in a local flag. Other possibility is use Interop stack item for Json (that supports null naturally).

[UPDATE] I tried this approach, but went worse than having another stackitem. Reason is that it brought incertainty to ByteArray internals, which is not good (at all). I'm supporting new stackitem Null now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants