Skip to content

Commit

Permalink
refactor: use deepCopy for eds.Flattened() (#315)
Browse files Browse the repository at this point in the history
Protect returned shares by `Flattened()` with deepcopy similar to other
exported methods
  • Loading branch information
walldiss authored Apr 10, 2024
1 parent 4c502ad commit e4b52cf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datasquare.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (ds *dataSquare) SetCell(x uint, y uint, newShare []byte) error {

// Flattened returns the concatenated rows of the data square.
func (ds *dataSquare) Flattened() [][]byte {
flattened := [][]byte(nil)
flattened := make([][]byte, 0, ds.width*ds.width)
for _, data := range ds.squareRow {
flattened = append(flattened, data...)
}
Expand Down
2 changes: 1 addition & 1 deletion extendeddatasquare.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (eds *ExtendedDataSquare) Width() uint {

// Flattened returns the extended data square as a flattened slice of bytes.
func (eds *ExtendedDataSquare) Flattened() [][]byte {
return eds.dataSquare.Flattened()
return deepCopy(eds.dataSquare.Flattened())
}

// FlattenedODS returns the original data square as a flattened slice of bytes.
Expand Down

0 comments on commit e4b52cf

Please sign in to comment.