Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/dtablefunctions/dolt_diff.go (Go)

Code before:
		rootVal, err = commit.GetRootValue(ctx)
		if err != nil {
			return fmt.Errorf("unable to load root value for schema override commit: %s", err.Error())
		}
	}

	var overriddenSchema schema.Schema
	if rootVal != nil {
		overriddenTable, _, ok, err := doltdb.GetTableInsensitive(ctx, rootVal, doltdb.TableName{Name: tableName})
		if err != nil {
			return fmt.Errorf("unable to find table '%s' at overridden schema root: %s", tableName, err.Error())
		}
		if !ok {
			return fmt.Errorf("unable to find table '%s' at overridden schema root", tableName)
		}

		overriddenSchema, err = overriddenTable.GetSchema(ctx)
		if err != nil {
			return fmt.Errorf("unable to load overridden schema for table '%s': %s", tableName, err.Error())
		}

		// The original schemas in |delta| are preserved for diff computation, which requires the original schemas to
		// compare rows. The overridden schema is applied when creating the [joiner] and when constructing
		// [DiffPartition] at execution time, where row converters map from the original schema to the overridden
		// schema.
		dtf.overriddenSchema = overriddenSchema
	} else {
		dtf.overriddenSchema = nil
	}

	fromTable, fromTableExists := delta.FromTable, delta.FromTable != nil
	toTable, toTableExists := delta.ToTable, delta.ToTable != nil

	var format *types.NomsBinFormat
	if toTableExists {
		format = toTable.Format()
	} else if fromTableExists {
		format = fromTable.Format()
	} else {
		return sql.ErrTableNotFound.New(tableName)
	}

	fromSchForJoiner := delta.FromSch
	toSchForJoiner := delta.ToSch
	if dtf.overriddenSchema != nil {
		fromSchForJoiner = dtf.overriddenSchema
		toSchForJoiner = dtf.overriddenSchema
	}

	diffTableSch, j, err := dtables.GetDiffTableSchemaAndJoiner(format, fromSchForJoiner, toSchForJoiner)
	if err != nil {

Review comment (security):
```suggestion
	if rootVal != nil {
		overriddenTable, _, ok, err := doltdb.GetTableInsensitive(ctx, rootVal, doltdb.TableName{Name: tableName})
		if err != nil {
			return fmt.Errorf("unable to find table '%s' at overridden schema root: %s", tableName, err.Error())
		}
		if !ok {
			return fmt.Errorf("unable to find table '%s' at overridden schema root", tableName)
		}

		overriddenSchema, err := overriddenTable.GetSchema(ctx)
		if err != nil {
			return fmt.Errorf("unable to load overridden schema for table '%s': %s", tableName, err.Error())
		}

		// The original schemas in |delta| are preserved for diff computation, which requires the original schemas to
		// compare rows. The overridden schema is applied when creating the [joiner] and when constructing
		// [DiffPartition] at execution time, where row converters map from the original schema to the overridden
		// schema.
		dtf.overriddenSchema = overriddenSchema
```

Code after:
		rootVal, err = commit.GetRootValue(ctx)
		if err != nil {
			return fmt.Errorf("unable to load root value for schema override commit: %s", err.Error())
		}
	}

	if rootVal != nil {
		overriddenTable, _, ok, err := doltdb.GetTableInsensitive(ctx, rootVal, doltdb.TableName{Name: tableName})
		if err != nil {
			return fmt.Errorf("unable to find table '%s' at overridden schema root: %s", tableName, err.Error())
		}
		if !ok {
			return fmt.Errorf("unable to find table '%s' at overridden schema root", tableName)
		}

		overriddenSchema, err := overriddenTable.GetSchema(ctx)
		if err != nil {
			return fmt.Errorf("unable to load overridden schema for table '%s': %s", tableName, err.Error())
		}

		// The original schemas in |delta| are preserved for diff computation, which requires the original schemas to
		// compare rows. The overridden schema is applied when creating the [joiner] and when constructing
		// [DiffPartition] at execution time, where row converters map from the original schema to the overridden
		// schema.
		dtf.overriddenSchema = overriddenSchema
	}

	fromTable, fromTableExists := delta.FromTable, delta.FromTable != nil
	toTable, toTableExists := delta.ToTable, delta.ToTable != nil

	var format *types.NomsBinFormat
	if toTableExists {
		format = toTable.Format()
	} else if fromTableExists {
		format = fromTable.Format()
	} else {
		return sql.ErrTableNotFound.New(tableName)
	}

	fromSchForJoiner := delta.FromSch
	toSchForJoiner := delta.ToSch
	if dtf.overriddenSchema != nil {
		fromSchForJoiner = dtf.overriddenSchema
		toSchForJoiner = dtf.overriddenSchema
	}

	diffTableSch, j, err := dtables.GetDiffTableSchemaAndJoiner(format, fromSchForJoiner, toSchForJoiner)
	if err != nil {
		return err
	}
	dtf.joiner = j