fix up some indexing in ParseSignature.

a test i was working on was crashing this otherwise. Make length checks more
paranoid.
test a bunch of invalid cases in ParseSignature.