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

Unmarshaling malicious data with variable-length array without specified size can lead to extensive memory usage #19

Closed
bartekn opened this issue Oct 27, 2016 · 1 comment

Comments

@bartekn
Copy link
Contributor

bartekn commented Oct 27, 2016

There is a bug in go-xdr (I wasn't able to create an issue there) when trying to unmarshal variable-length array without specified size. Take a look at this union:

union StellarMessage switch (MessageType type)
{
  // ...

case GET_PEERS:
    void;
case PEERS:
    PeerAddress peers<>;

  // ...
}

We can create a special StellarMessage that looks like:

$ echo "AAAABX///9AAAAAAAAECAwAAAFAAAABk" | base64 -D | hexdump -C
00000000  00 00 00 05 7f ff ff d0  00 00 00 00 00 01 02 03  |................|
                      ^^^^^^^^^^^
00000010  00 00 00 50 00 00 00 64                           |...P...d|
00000018

Bytes marked with ^ represent the size of an array, which should be 1 since it contains only one address, but it has been changed to some very large number. As a result go-xdr is trying to allocate a large chunk of memory for the array that in reality is really small. Here's a little proof-of-concept:

package main

import (
  "github.com/stellar/go/xdr"
)

func main() {
  var message xdr.StellarMessage
  xdr.SafeUnmarshalBase64("AAAABX///9AAAAAAAAECAwAAAFAAAABk", &message)
}

A fix should check if the number of remaining bytes is less than or equal the specified size before allocating memory (you can check how it's works in xdrpp).

@nullstyle
Copy link
Contributor

Let's move this to go-xdr. Issues being disabled on that repo was an accident.

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

No branches or pull requests

2 participants