0

I use NSStream to send data over through MCSession, this works fine 99%, however sometimes i get trash on the receiver's end

I write

First 4 bytes is the hash
Next 4 bytes is the content length
Rest the data

in case of trash, i get wild values like the content length too large, hash incorrect...

How to defend against such input? now i can check that hash don't match, but a problem can raise, if the "content length" gets larger than the buffer

Note: that NSStreamEventErrorOccurred doe not get triggered

Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179

1 Answers1

0

i add common 4 byte assurance (like number 42) and check on the receivers end...

now this may fail in 0.000000001% but still didn't found better alternative

But open to other answers us well

Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179