Skip to content

Commit

Permalink
Delete Null characters from Logs (#739)
Browse files Browse the repository at this point in the history
This commit strips null characters from logs, which should fix indexers from crashing.

Closes #735
  • Loading branch information
algochoi authored Oct 15, 2021
1 parent c202884 commit 6f0ebc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions idb/postgres/internal/encoding/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package encoding

import (
"encoding/base64"
"unicode"
"unicode/utf8"

sdk_types "github.com/algorand/go-algorand-sdk/types"
"github.com/algorand/go-codec/codec"
Expand Down Expand Up @@ -81,7 +83,33 @@ func convertLocalDeltas(deltas map[uint64]types.StateDelta) map[uint64]types.Sta
return res
}

// printableUTF8OrEmpty checks to see if the entire string is a UTF8 printable string.
// If this is the case, the string is returned as is. Otherwise, the empty string is returned.
func printableUTF8OrEmpty(in string) string {
// iterate throughout all the characters in the string to see if they are all printable.
// when range iterating on go strings, go decode each element as a utf8 rune.
for _, c := range in {
// is this a printable character, or invalid rune ?
if c == utf8.RuneError || !unicode.IsPrint(c) {
return ""
}
}
return in
}

func removeNonUTF8Chars(logs []string) []string {
if logs == nil {
return nil
}
res := make([]string, len(logs))
for i, log := range logs {
res[i] = printableUTF8OrEmpty(log)
}
return res
}

func convertEvalDelta(evalDelta types.EvalDelta) types.EvalDelta {
evalDelta.Logs = removeNonUTF8Chars(evalDelta.Logs)
evalDelta.GlobalDelta = convertStateDelta(evalDelta.GlobalDelta)
evalDelta.LocalDeltas = convertLocalDeltas(evalDelta.LocalDeltas)
return evalDelta
Expand Down
2 changes: 1 addition & 1 deletion misc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN echo "Go image: $GO_IMAGE"
# Misc dependencies
ENV HOME /opt
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y apt-utils curl git git-core bsdmainutils python3 python3-pip make
RUN apt-get update && apt-get install -y apt-utils curl git git-core bsdmainutils python3 python3-pip make libffi-dev build-essential

# Install algod nightly binaries to the path
RUN mkdir -p /opt/algorand/{bin,data}
Expand Down

0 comments on commit 6f0ebc2

Please sign in to comment.