hk
If a length or data call is issued for an integer, should it attempt to recover by correcting it or return an error?
orignal
drop
hk
thank you
zzz
huh?
orignal
I assume he is asking what we do with messages with invalid lenght
orignal
like too long or too short
hk
zzz: sorry I mispoke, it's in regards to I2PStrings, not integers my bad
dr|z3d
if go's anything like java, you may need null checks.
hk
but the same principle applies, not messages sorry. If you create an i2p string programatically and the length is invalid, should it attempt to trim the data in attempt to recover and/or return an error
hk
hm
dr|z3d
if (string.length() > 10) {string = string.substring(0,7) + "...";}
hk
nuyeah I see what you mean, whether to do that or return an error essentially
hk
yeah*
dr|z3d
depends on context, what you're doing.
dr|z3d
maybe > 10 is invalid, then you'd want to drop it and print an error.
hk
func (str I2PString) Data() (data string, err error) {
hk
length, err := str.Length()
hk
if err != nil {
hk
switch err {
hk
case ErrDataTooLong:
hk
log.WithError(err).Warn("I2PString contains data beyond specified length")
hk
data = string(str[1:])
hk
//data = string(str[1 : length+1]) // Should we recover and trim?
hk
return
zzz
how would you know if what comes after is 'extra' or just the next field in the data structure?
zzz
a: you don't
zzz
the string tells you how long it is, it can't be "wrong"
hk
understood
orignal
really? first byte says 255 while length of remianing buffer is 100
orignal
you must alway check this
zzz
well you can never tell if 'too short' unless last item in the structure.
zzz
sure it could be too long but presumably you have protection for that, that's not unique to strings, any field could be longer than what's remaining
zzz
but no, you never try to "recover" by correcting something invalid
hk
got it got it
zzz
but doesn't Go do bounds checks on byte arrays so you can't overrun them, just like Java? eyedeekay?
zzz
if so, I assume the best practice is to NOT explicitly check for overrun, let the panic equivalent of AIOOBE get thrown, and catch it higher up
zzz
but that's up to you guys to come up with and adhere to a coding style
hk
AIOOBE?