Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7555721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:40:55+00:00 2026-05-30T11:40:55+00:00

I had protobuf.net deserialize invalid (random) bytes into a KeyValuePair (i.e. not nullable). Instead

  • 0

I had protobuf.net deserialize invalid (random) bytes into a KeyValuePair (i.e. not nullable). Instead of (as expected) an exception being thrown, an empty struct was returned.

Since this default struct could be valid data, I don’t see a way to tell if the source data are actually valid. Is this a bug, or is there a way I’m missing?

(protobuf-net 2.0.0.480, 2011.12.11)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:40:56+00:00Added an answer on May 30, 2026 at 11:40 am

    Update:

    There were scenarios in v2 where it wouldn’t spot this, but would instead terminate as though it had reached the end of the stream – in particular if the “field number”, after applying shifts, was non-positive. However, this is not valid in a protobuf stream, and this will be fixed next build.


    That depends on quite how random it was ;p Actually, getting that to do anything without throwing an error is pretty impressive – the protobuf spec is pretty specific about layout, and normally it will throw a big exception there (probably mentioning “unexpected wire-type” or similar).

    Emphasis: in almost all cases it will throw an exception. If you fluke some data of the right spec, but different field numbers, then it will silently ignore the unexpected data, and you’ll get an all-zero struct. If you fluke some data of the right spec, but with the right field numbers and layout, you’ll get garbage. But that is like saying

    if I randomly generate data that by pure chance happens to be {"foo":"0"}, JavascriptSerializer doesn’t complain!!! bug!!!

    Are you sure you actually deserialized some data here? and that the stream wasn’t already the EOF position? For example, the following won’t error, as you haven’t rewound the stream – you are effective deserializing zero bytes:

    var ms = new MemoryStream();
    ms.Write(randomBytes, 0, randomBytes.Length);
    var obj = Serializer.Deserialize<Foo>(ms);
    

    (and zero bytes is perfectly valid for a protobuf object)

    If you want to test a stream for validity, you can use ProtoReader, just skipping (SkipField() or something similar) every field until ReadNextHeader() (or whatever) returns a non-positive integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a discussion with some colleagues mentioning that there are not too many
Had something weird start happening to me today. I have an asp.net mvc app
Had a Windows Forms app using a WebBrowser control (.NET 4) to load a
To Serialize a class with protobuf-net, you neet to provide the class and property
Had a facebook tab called "Sign Up" as a gateway into an iframe canvas
Had this interesting question being asked today and the arguments varied from Proxy to
Had I looked into the Java SE6 documentation sooner on Context and InitialContext, I
Had there been no System.Random class, how would have you generated a random number?
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
Had a coworker ask me this, and in my brain befuddled state I didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.