Skip to content

Commit

Permalink
fix: payloadsize calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Nov 15, 2023
1 parent 6e458cc commit 56e0577
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/file/joiner/joiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func New(ctx context.Context, getter storage.Getter, address swarm.Address) (fil
}
rootParity, span := chunkToSpan(chunkData)
maxBranching := swarm.ChunkSize / refLength
payloadSize, err := chunkPayloadSize(rootData)
if err != nil {
return nil, 0, err
payloadSize := int(span)
if span > swarm.ChunkSize {
payloadSize, err = chunkPayloadSize(rootData)
if err != nil {
return nil, 0, err
}
}
rootShards := payloadSize - (rootParity*swarm.HashSize)/refLength
rLevel, err := redundancy.GetLevel(rootParity, rootShards, encryption)
Expand All @@ -69,7 +72,7 @@ func New(ctx context.Context, getter storage.Getter, address swarm.Address) (fil
return 0, int64(bmt.LengthFromSpan(data[:swarm.SpanSize]))
}
// override stuff if root chunk has redundancy
if rootParity > 0 {
if rLevel != redundancy.NONE {
spanFn = chunkToSpan
if encryption {
maxBranching = rLevel.GetMaxEncShards()
Expand Down Expand Up @@ -357,7 +360,7 @@ func (j *joiner) Size() int64 {
// chunkPayloadSize returns the effective byte length of an intermediate chunk
// assumes data is always chunk size (without span)
func chunkPayloadSize(data []byte) (int, error) {
l := swarm.ChunkSize
l := len(data)
for l > swarm.HashSize {
if !bytes.Equal(data[l-swarm.HashSize:l], swarm.ZeroAddress.Bytes()) {
return l, nil
Expand Down

0 comments on commit 56e0577

Please sign in to comment.