mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
cli: verify index file construction in upload-bin
command
Verify that there are no empty OIDs in the constructed index file, as empty payloads can result in improperly set attributes, leading to empty OIDs being added to the index file. Close #3628 Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
42c8e40eaa
commit
a5e9ab6979
1 changed files with 11 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -346,6 +347,8 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
|
||||||
buffer = make([]byte, indexFileSize*oidSize)
|
buffer = make([]byte, indexFileSize*oidSize)
|
||||||
oidCh = make(chan oid.ID, indexFileSize)
|
oidCh = make(chan oid.ID, indexFileSize)
|
||||||
oidFetcherToProcessor = make(chan struct{}, indexFileSize)
|
oidFetcherToProcessor = make(chan struct{}, indexFileSize)
|
||||||
|
|
||||||
|
emptyOid = make([]byte, oidSize)
|
||||||
)
|
)
|
||||||
defer close(oidCh)
|
defer close(oidCh)
|
||||||
for range maxParallelSearches {
|
for range maxParallelSearches {
|
||||||
|
@ -426,6 +429,14 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if there are any empty oids in the created index file.
|
||||||
|
// This could happen if object payload is empty ->
|
||||||
|
// attribute is not set correctly -> empty oid is added to the index file.
|
||||||
|
for k := 0; k < len(buffer); k += oidSize {
|
||||||
|
if slices.Compare(buffer[k:k+oidSize], emptyOid) == 0 {
|
||||||
|
return fmt.Errorf("empty oid found in index file %d at position %d (block index %d)", i, k/oidSize, i+uint(k/oidSize))
|
||||||
|
}
|
||||||
|
}
|
||||||
attrs := []object.Attribute{
|
attrs := []object.Attribute{
|
||||||
*object.NewAttribute(attributeKey, strconv.Itoa(int(i))),
|
*object.NewAttribute(attributeKey, strconv.Itoa(int(i))),
|
||||||
*object.NewAttribute("IndexSize", strconv.Itoa(int(indexFileSize))),
|
*object.NewAttribute("IndexSize", strconv.Itoa(int(indexFileSize))),
|
||||||
|
|
Loading…
Reference in a new issue