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

MessagePackSerializer.Deserialize<dynamic> hangs permanently #359

Closed
Metalnem opened this issue Dec 28, 2018 · 3 comments
Closed

MessagePackSerializer.Deserialize<dynamic> hangs permanently #359

Metalnem opened this issue Dec 28, 2018 · 3 comments
Milestone

Comments

@Metalnem
Copy link

The following C# program hangs permanently:

namespace MessagePack.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var bytes = new byte[]
      {
        0x8E, 0x80, 0xFF, 0x74, 0x6F, 0x0E, 0x41, 0xDF, 0x74,
        0x6F, 0x0E, 0x41, 0x90, 0x00, 0x00, 0x0F, 0x7B, 0x20,
        0x8E, 0x80, 0xFF, 0x74, 0x6F, 0x0E, 0x41, 0xDF, 0x74,
        0x6F, 0x0E, 0x41, 0x90, 0x00, 0x00, 0xF8, 0x7A, 0x20,
        0x70, 0x68, 0x00, 0xDF, 0x6F, 0x90, 0x1C, 0x6F, 0x74,
        0x6F, 0x61, 0x70, 0x68, 0x00, 0xDF, 0x52, 0x90, 0x1C,
        0x6F, 0x74, 0x6F, 0x61, 0x6D, 0x01, 0x02, 0x03, 0x04
      };

      MessagePackSerializer.Deserialize<dynamic>(bytes);
    }
  }
}

Found via SharpFuzz.

@itn3000
Copy link
Contributor

itn3000 commented Jan 7, 2019

In my env, OutOfMemoryException occurred(win81-x64).
MessagePack.dll seems to interprete the data as follows(msgpack spec is here);

  1. 0x8e = fixmap, length = 14(let's say "mapA")
  2. 0x80 = fixmap, length = 0(1st mapA key)
  3. 0xff = negative fixint = -1(1st mapA value)
  4. 0x74 = positive fixint = 0x74(2nd mapA key)
  5. 0x6f = positive fixint = 0x6f(2nd mapA value)
  6. 0x0e = positive fixint = 0x0e(3rd mapA key)
  7. 0x41 = positive fixint = 0x41(3rd mapA value)
  8. 0xdf = map32(4th mapA key)
  9. 0x74, 0x6f, 0x0e, 0x41 = map32 length(0x746f0e41 = 1953435201)
  10. do new Dictionary<object, object>(1953435201)

this is very large object, so program may be freeze or throw OutOfMemoryException(depending on the environment)

I think the decoder should throw any Exception in processing(perhaps IndexOutOfRangeException?) if map or array length is exceeded remaining data length.

@Metalnem
Copy link
Author

Metalnem commented Jan 9, 2019

This is interesting. I've tried it on .NET Framework 4.7.2, and I also got OutOfMemoryException, but on .NET Core 2.1 this program hangs on both Windows and macOS. This looks like it could actually be some .NET Core bug. I'll investigate this a bit further!

@AArnott
Copy link
Collaborator

AArnott commented Dec 6, 2019

Fixed in 2.0 (it no longer hangs, but throws instead).

@AArnott AArnott closed this as completed Dec 6, 2019
@AArnott AArnott added this to the v2.0 milestone Dec 6, 2019
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

3 participants