Skip to content

Commit b93ffd8

Browse files
authored
fix: search and replace null bytes for postgres only.Fixes #13711 (#14030)
Signed-off-by: isubasinghe <[email protected]>
1 parent ef41f83 commit b93ffd8

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

persist/sqldb/workflow_archive.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package sqldb
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
7+
"strings"
68
"time"
79

810
log "github.com/sirupsen/logrus"
@@ -20,8 +22,9 @@ import (
2022
)
2123

2224
const (
23-
archiveTableName = "argo_archived_workflows"
24-
archiveLabelsTableName = archiveTableName + "_labels"
25+
archiveTableName = "argo_archived_workflows"
26+
archiveLabelsTableName = archiveTableName + "_labels"
27+
postgresNullReplacement = "ARGO_POSTGRES_NULL_REPLACEMENT"
2528
)
2629

2730
type archivedWorkflowMetadata struct {
@@ -103,6 +106,9 @@ func (r *workflowArchive) ArchiveWorkflow(wf *wfv1.Workflow) error {
103106
if err != nil {
104107
return err
105108
}
109+
if r.dbType == Postgres {
110+
workflow = bytes.ReplaceAll(workflow, []byte("\\u0000"), []byte(postgresNullReplacement))
111+
}
106112
return r.session.Tx(func(sess db.Session) error {
107113
_, err := sess.SQL().
108114
DeleteFrom(archiveTableName).
@@ -387,6 +393,9 @@ func (r *workflowArchive) GetWorkflow(uid string, namespace string, name string)
387393
return nil, err
388394
}
389395
var wf *wfv1.Workflow
396+
if r.dbType == Postgres {
397+
archivedWf.Workflow = strings.ReplaceAll(archivedWf.Workflow, postgresNullReplacement, "\\u0000")
398+
}
390399
err = json.Unmarshal([]byte(archivedWf.Workflow), &wf)
391400
if err != nil {
392401
return nil, err

test/e2e/argo_server_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,42 @@ func (s *ArgoServerSuite) TestRateLimitHeader() {
21352135
})
21362136
}
21372137

2138+
func (s *ArgoServerSuite) TestPostgresNullBytes() {
2139+
// only meaningful for postgres, but shouldn't fail for mysql.
2140+
var uid types.UID
2141+
_ = uid
2142+
2143+
s.Given().
2144+
Workflow(`
2145+
metadata:
2146+
generateName: archie-
2147+
labels:
2148+
foo: 1
2149+
spec:
2150+
entrypoint: run-archie
2151+
templates:
2152+
- name: run-archie
2153+
container:
2154+
image: argoproj/argosay:v2
2155+
args: [echo, "hello \u0000"]`).
2156+
When().
2157+
SubmitWorkflow().
2158+
WaitForWorkflow(fixtures.ToBeArchived).
2159+
Then().
2160+
ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
2161+
uid = metadata.UID
2162+
})
2163+
2164+
j := s.e().GET("/api/v1/archived-workflows/{uid}", uid).
2165+
Expect().
2166+
Status(200).
2167+
JSON()
2168+
j.
2169+
Path("$.spec.templates[0].container.args[1]").
2170+
IsEqual("hello \u0000")
2171+
2172+
}
2173+
21382174
func TestArgoServerSuite(t *testing.T) {
21392175
suite.Run(t, new(ArgoServerSuite))
21402176
}

0 commit comments

Comments
 (0)