From 242edda60bedf1f4ff1994eb20c74129ef33b286 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Tue, 26 Jan 2021 16:51:24 -0800 Subject: [PATCH] Added a failsafe validation for schemas about to be written to disk. --- go/libraries/doltcore/schema/encoding/schema_marshaling.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go/libraries/doltcore/schema/encoding/schema_marshaling.go b/go/libraries/doltcore/schema/encoding/schema_marshaling.go index 149245236d..2ae2f82ec4 100644 --- a/go/libraries/doltcore/schema/encoding/schema_marshaling.go +++ b/go/libraries/doltcore/schema/encoding/schema_marshaling.go @@ -224,6 +224,13 @@ func (sd schemaData) decodeSchema() (schema.Schema, error) { // MarshalSchemaAsNomsValue takes a Schema and converts it to a types.Value func MarshalSchemaAsNomsValue(ctx context.Context, vrw types.ValueReadWriter, sch schema.Schema) (types.Value, error) { + // Anyone calling this is going to serialize this to disk, so it's our last line of defense against defective schemas. + // Business logic should catch errors before this point, but this is a failsafe. + err := schema.ValidateForInsert(sch.GetAllCols()) + if err != nil { + return nil, err + } + sd, err := toSchemaData(sch) if err != nil {