guard event and filter decoders against bad-sized hexes.
This commit is contained in:
@@ -27,9 +27,15 @@ func easyjsonDecodeEvent(in *jlexer.Lexer, out *Event) {
|
|||||||
}
|
}
|
||||||
switch key {
|
switch key {
|
||||||
case "id":
|
case "id":
|
||||||
hex.Decode(out.ID[:], in.UnsafeBytes())
|
b := in.UnsafeBytes()
|
||||||
|
if len(b) == 32 {
|
||||||
|
hex.Decode(out.ID[:], b)
|
||||||
|
}
|
||||||
case "pubkey":
|
case "pubkey":
|
||||||
hex.Decode(out.PubKey[:], in.UnsafeBytes())
|
b := in.UnsafeBytes()
|
||||||
|
if len(b) == 32 {
|
||||||
|
hex.Decode(out.PubKey[:], b)
|
||||||
|
}
|
||||||
case "created_at":
|
case "created_at":
|
||||||
out.CreatedAt = Timestamp(in.Int64())
|
out.CreatedAt = Timestamp(in.Int64())
|
||||||
case "kind":
|
case "kind":
|
||||||
@@ -65,7 +71,10 @@ func easyjsonDecodeEvent(in *jlexer.Lexer, out *Event) {
|
|||||||
case "content":
|
case "content":
|
||||||
out.Content = in.String()
|
out.Content = in.String()
|
||||||
case "sig":
|
case "sig":
|
||||||
hex.Decode(out.Sig[:], in.UnsafeBytes())
|
b := in.UnsafeBytes()
|
||||||
|
if len(b) == 64 {
|
||||||
|
hex.Decode(out.Sig[:], b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
in.WantComma()
|
in.WantComma()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ func easyjsonDecodeFilter(in *jlexer.Lexer, out *Filter) {
|
|||||||
}
|
}
|
||||||
for !in.IsDelim(']') {
|
for !in.IsDelim(']') {
|
||||||
id := [32]byte{}
|
id := [32]byte{}
|
||||||
hex.Decode(id[:], in.UnsafeBytes())
|
b := in.UnsafeBytes()
|
||||||
|
if len(b) == 32 {
|
||||||
|
hex.Decode(id[:], b)
|
||||||
|
}
|
||||||
out.IDs = append(out.IDs, id)
|
out.IDs = append(out.IDs, id)
|
||||||
in.WantComma()
|
in.WantComma()
|
||||||
}
|
}
|
||||||
@@ -74,7 +77,10 @@ func easyjsonDecodeFilter(in *jlexer.Lexer, out *Filter) {
|
|||||||
}
|
}
|
||||||
for !in.IsDelim(']') {
|
for !in.IsDelim(']') {
|
||||||
pk := [32]byte{}
|
pk := [32]byte{}
|
||||||
hex.Decode(pk[:], in.UnsafeBytes())
|
b := in.UnsafeBytes()
|
||||||
|
if len(b) == 32 {
|
||||||
|
hex.Decode(pk[:], b)
|
||||||
|
}
|
||||||
out.Authors = append(out.Authors, pk)
|
out.Authors = append(out.Authors, pk)
|
||||||
in.WantComma()
|
in.WantComma()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user