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

RPC interface seems to silently ignore too-large numbers #219

Open
dooglus opened this issue Aug 27, 2015 · 5 comments
Open

RPC interface seems to silently ignore too-large numbers #219

dooglus opened this issue Aug 27, 2015 · 5 comments
Labels

Comments

@dooglus
Copy link
Collaborator

dooglus commented Aug 27, 2015

I recently tried to list the unspent inputs in my wallet. Since there's no way I know of to ask for "all of them, mature or not", I typically ask for those with between 0 and 9999999999 confirmations, from any address, mature-or-not, like this:

$ clamd listunspent 0 99999999999 | grep amount | wc -l
45

... and that works. But this time I put too many 9's, and it returned an empty list:

$ clamd listunspent 0 999999999999
[
]

It seems the extra 9 must have made the integer overflow, probably making it go negative, and so no outputs were found to match.

That's eleven 9's works, and twelve 9's doesn't.

Indeed, it's at 2^31 that the issue first happens:

$ clamd listunspent 0 $((2**31 - 1)) | grep amount | wc -l
47

$ clamd listunspent 0 $((2**31)) | grep amount | wc -l
0
@creativecuriosity
Copy link
Collaborator

In the RPCTypeCheck method @ https://github.com/nochowderforyou/clams/blob/master/src/rpcserver.cpp#L45

string err = strprintf("Expected type %s, got %s",
                                   Value_type_name[t], Value_type_name[v.type()]);
            throw JSONRPCError(RPC_TYPE_ERROR, err);

It appears this bug will display odd/overflow behavior with any RPC command executed with the standard int_type check?

I would assume fixing the call to *.type() might fix the underlying error as opposed to injecting additional checks into the listunspent method itself.

@creativecuriosity
Copy link
Collaborator

Ref: bitcoin/bitcoin#6765

@l0rdicon
Copy link
Collaborator

l0rdicon commented Oct 9, 2015

This is fixed in the update from json_spirit to UniValue.

#236

Is the pull request but has not been fully tested yet.

createrawtransaction and signrawtransaction especially need to be tested still.

@tryphe
Copy link
Collaborator

tryphe commented Sep 2, 2016

This looks fixed so I'm going to close it. The test numbers you see here are 31 signed bits filled and +1.

$ cct listunspent 2147483647
[
]

$ cct getblockbynumber 2147483647
error code: -1
error message: Block number out of range.

$ cct listunspent 2147483648
error code: -1
error message: JSON integer out of range

$ cct getblockbynumber 2147483648
error code: -1
error message: JSON integer out of range

@tryphe tryphe closed this as completed Sep 2, 2016
@tryphe
Copy link
Collaborator

tryphe commented Sep 2, 2016

I'll try and test createrawtransaction and signrawtransaction soon

@tryphe tryphe reopened this Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants