You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Thank you for creating this library. It seems very useful. I was playing around with the example in the README and playing with corrupting the data.
Eventually I succeeded at corrupting it enough that it would not recover, but it would also not error, thus recovering faulty data... Try this:
package main
import (
"fmt""github.com/vivint/infectious"
)
funcmain() {
const (
required=8total=14
)
// Create a *FEC, which will require required pieces for reconstruction at// minimum, and generate total total pieces.f, err:=infectious.NewFEC(required, total)
iferr!=nil {
panic(err)
}
// Prepare to receive the shares of encoded data.shares:=make([]infectious.Share, total)
output:=func(s infectious.Share) {
// the memory in s gets reused, so we need to make a deep copyshares[s.Number] =s.DeepCopy()
}
// the data to encode must be padded to a multiple of required, hence the// underscores.text:="hello, world! __"err=f.Encode([]byte(text), output)
iferr!=nil {
panic(err)
}
fmt.Println("----------------")
fmt.Println("Generated shares:")
// we now have total shares.for_, share:=rangeshares {
fmt.Printf("%d: %#v\n", share.Number, string(share.Data))
}
// Let's reconstitute with shares 0-5 missing and 1 piece corrupted.shares=shares[6:]
shares[2].Data[1] ='!'// mutate some datafmt.Println("----------------")
fmt.Println("Fucked shares:")
for_, share:=rangeshares {
fmt.Printf("%d: %#v\n", share.Number, string(share.Data))
}
err=f.Correct(shares)
iferr!=nil {
panic(err)
}
result, err:=f.Decode(nil, shares)
iferr!=nil {
panic(err)
}
// we have the original data!fmt.Println("----------------")
fmt.Println("Fixed shares:")
fmt.Printf("original text: %#v\n", string(text))
fmt.Printf("recovered text: %#v\n", string(result))
}
In this example I require 8 "good" shares to recover. I have 8 shares, but 1 of them is corrupt, so technically I only have 7 good shares, which is not enough to decode this... yet no panic.
That's weird, no? I guess there's something I'm not understanding but I would have expected an error value if the data was too corrupt.
Now if I replace:
// Let's reconstitute with shares 0-5 missing and 1 piece corrupted.shares=shares[6:]
shares[2].Data[1] ='!'// mutate some data
Hi! Thank you for creating this library. It seems very useful. I was playing around with the example in the README and playing with corrupting the data.
Eventually I succeeded at corrupting it enough that it would not recover, but it would also not error, thus recovering faulty data... Try this:
You can try the snippet above in the playground: https://play.golang.org/p/ueV5p2O6QE5
It does not panic at all; printing:
In this example I require 8 "good" shares to recover. I have 8 shares, but 1 of them is corrupt, so technically I only have 7 good shares, which is not enough to decode this... yet no panic.
That's weird, no? I guess there's something I'm not understanding but I would have expected an error value if the data was too corrupt.
Now if I replace:
...with a few mutations too many:
I get:
panic: too many errors to reconstruct
which is the kind of error I'd expect to get with my first snippet instead of decoding garbage data.Is it a bug? or a weird edge case where the algorithm breaks?
The text was updated successfully, but these errors were encountered: