Compare commits

...
Author SHA1 Message Date
Arkadiy Tetelman e5815840e4 Merge pull request #15 from hugoharman/main
Fix overly strict error handling causing valid protos to be skipped
2025-10-19 14:36:42 -07:00
Arkadiy Tetelman 08f630f96e Merge branch 'main' into main 2025-10-19 14:34:36 -07:00
Arkadiy Tetelman 8b8af09dcb Merge pull request #17 from arkadiyt/atetelman--actions
Add pull_request_target
2025-10-19 14:34:25 -07:00
Arkadiy Tetelman e012331a33 Merge branch 'main' into main 2025-10-19 14:17:55 -07:00
hugoharman dcbafdb247 Fix overly strict error handling causing valid protos to be skipped 2025-07-29 21:40:08 +07:00
+20 -4
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"os"
"strings"
"google.golang.org/protobuf/encoding/protowire"
)
@@ -15,12 +16,22 @@ func consumeBytes(data []byte, position int) (int, error) {
start := position
consumedFieldOne := false
for {
number, _, len := protowire.ConsumeField(data[position:])
if len < 0 {
err := protowire.ParseError(len)
number, _, length := protowire.ConsumeField(data[position:])
if length < 0 {
err := protowire.ParseError(length)
// Treat "invalid field number" as end of data, not an error
if strings.Contains(err.Error(), "invalid field number") {
return position - start, nil
}
// Return other parse errors as actual errors
return position - start, fmt.Errorf("couldn't consume proto bytes: %w", err)
}
// Prevent infinite loop - if we can't consume any bytes, we're done
if length == 0 {
return position - start, nil
}
// Only consume Field 1 once (to handle the case where protobuf definitions are adjacent
// in program memory)
if number == 1 {
@@ -30,7 +41,12 @@ func consumeBytes(data []byte, position int) (int, error) {
consumedFieldOne = true
}
position += len
position += length
// Additional safety check - don't read beyond data bounds
if position-start >= len(data[start:]) {
return position - start, nil
}
}
}