Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework multipart handling without tree service #1087

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

smallhive
Copy link
Contributor

No description provided.

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Closes #1068.

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
maxKeys = 1000
}

opts.SetCount(uint32(maxKeys))

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type uint32 without an upper bound check.

Copilot Autofix AI 2 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

}

if copies, err := strconv.ParseUint(payloadMap[metaKeyMultipartCopiesNumber], 10, 64); err == nil {
multipartInfo.CopiesNumber = uint32(copies)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an unsigned 64-bit integer from
strconv.ParseUint
to a lower bit size type uint32 without an upper bound check.

Copilot Autofix AI 2 days ago

To fix the problem, we need to add an upper bound check to ensure that the value parsed from the string fits within the uint32 range before converting it. This can be done by comparing the parsed uint64 value against the maximum value of uint32 (math.MaxUint32). If the value exceeds this limit, we should handle it appropriately, such as by returning an error or using a default value.

Suggested changeset 1
api/layer/multipart_upload.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/layer/multipart_upload.go b/api/layer/multipart_upload.go
--- a/api/layer/multipart_upload.go
+++ b/api/layer/multipart_upload.go
@@ -17,2 +17,3 @@
 	"strconv"
+	"math"
 	"strings"
@@ -902,2 +903,5 @@
 	if copies, err := strconv.ParseUint(payloadMap[metaKeyMultipartCopiesNumber], 10, 64); err == nil {
+		if copies > math.MaxUint32 {
+			return data.MultipartInfo{}, fmt.Errorf("copies number exceeds uint32 limit: %d", copies)
+		}
 		multipartInfo.CopiesNumber = uint32(copies)
EOF
@@ -17,2 +17,3 @@
"strconv"
"math"
"strings"
@@ -902,2 +903,5 @@
if copies, err := strconv.ParseUint(payloadMap[metaKeyMultipartCopiesNumber], 10, 64); err == nil {
if copies > math.MaxUint32 {
return data.MultipartInfo{}, fmt.Errorf("copies number exceeds uint32 limit: %d", copies)
}
multipartInfo.CopiesNumber = uint32(copies)
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant