Fix two more bugs.

Unfortunately, two more subtle bugs to fix:

- If the encoded protobuf message is only three bytes long (or less),
  not only the whole protobuf will fit into headerBuf, but also the
  beginning of the next length varint. This will completely wreak
  havoc in the read process. (This bug never bit us in Prometheus
  because the protobuf messages were all long enough. But protobufs in
  general can be very small (0 bytes in fact). I added a test for
  that.)

- If the reader stops in the middle of a length varint, it will
  interpret the null byte that is already in headerBuf as the final
  byte of the varint, which again wreaks havoc. (This bug only shows
  up in Prometheus after
  https://github.com/prometheus/prometheus/commit/dfb9c2a072d5c1003e78c4921988c21bc76ab07a
  , and it is very rare... needs very unlucky fragmentation on the
  network.)

Solution to the first bug is to read byte-wise, which is slightly less
effective, but simplifies the code later, because we don't "overshoot"
anymore. Solution to the second bug is to only read the parts of
headerBuf that have been written to.
If an implementer of io.Reader doesn't stick to the contract, it will create bugs. That does not change if we try to defend against it in this particular case. I'm not sure what you are aiming at here. The scenario I described above is legit. If we report an error in that case, we would break reading the "empty" protocol message. That's not a corrupt header.

#6 looks pretty advanced. Happy to review it at my earliest convenience. Just not now that I have to run from the one war room to the other... I need to take my time for that.

How about merging this PR first? That would avoid that the poor overworked guy over here has to repeatedly merge what is a fix for a bug that is in the wild and breaking things out there right now. Arguably, the further improvements of the tests are general purpose and not for this particular bug (which is exposed by the existing tests already).