← Back to Pull requests

Solve G115 Linter Errors #4193

Merged
HoustonBoston merged 10 files (209 lines) on Oct 01, 2026 13:05 UTC
View on GitHub
HoustonBoston HoustonBoston commented on Jul 01, 2026 20:25 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:
1. Follow the instructions for writing a release note from k8s: https://git.k8s.io/community/contributors/guide/release-notes.md
-->

What this PR does / why we need it:

Rather than excluding G115 for linting globally, this fix evaluates type conversions on a case-by-case basis, changing types of variables and completely ignoring the integer conversion where applicable so that linting succeeds.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3656.

Special notes for your reviewer:

Release note:
<!-- Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
``release-note
NONE
``

Diff: 209 lines (+156 / -53) across 10 files Reviewer: awels Review duration: 132039m
All Vouch review confidence checks passed
Residual risk 0.12 = Change Risk (0.48) × (1 − Review Confidence (0.75)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 209 lines diff across 10 files
0.48
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.50 · 5 substantive comment(s)
0.50
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
74%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.320
Real PR Conversation Timeline
55 items
kubevirt-prow[bot] kubevirt-prow[bot] commented on Jul 01, 2026 20:25 UTC
Bot

Hi @HoustonBoston. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

<details>

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>

dsanatar dsanatar commented on Jul 02, 2026 11:57 UTC
Contributor

/test all

coveralls coveralls commented on Jul 02, 2026 12:13 UTC
Contributor

![Coverage Status](https://coveralls.io/builds/82073164)

coverage: 49.807% (-0.05%) from 49.859% — HoustonBoston:fix-g115-linting into kubevirt:main

dsanatar dsanatar commented on Jul 02, 2026 16:05 UTC
Contributor

/test all

HoustonBoston HoustonBoston commented on Jul 08, 2026 15:36 UTC
Author

/test pull-containerized-data-importer-e2e-s390x

akalenyu akalenyu commented on Jul 13, 2026 12:40 UTC
Contributor

/cc

akalenyu akalenyu commented on Jul 14, 2026 14:47 UTC
Reviewer

Thanks for tackling this!
We're definitely going to keep nolints on some specific cases, but I was wondering if we
could get rid of the nolints where the value is known to be non-negative by domain (lengths, sizes, offsets)?

Here's a reference to a large project enabling G115 that may help - https://github.com/elastic/cloud-on-k8s/pull/9302

HoustonBoston HoustonBoston commented on Aug 04, 2026 15:55 UTC
Author

/test pull-containerized-data-importer-e2e-ceph

awels awels approved these changes on Aug 06, 2026 14:47 UTC
Approved Reviewer

Approved these changes.

akalenyu akalenyu commented on code on Aug 11, 2026 20:13 UTC
Code Review
cmd/cdi-controller/controller.go:1
@@ -372,7 +373,7 @@ func main() {
 		klog.Fatalf("Unable to get environment variables: %v\n", errors.WithStack(err))
 	}
 
-	logf.SetLogger(zap.New(zap.Level(zapcore.Level(-1*verbosityLevel)), zap.UseDevMode(debug)))
+	logf.SetLogger(zap.New(zap.Level(zapcore.Level(-1*int8(min(verbosityLevel, math.MaxInt8)))), zap.UseDevMode(debug))) //nolint:gosec // G115: clamped to MaxInt8 above

do you still need the nolint? that's weird

akalenyu akalenyu commented on code on Aug 11, 2026 20:14 UTC
Code Review
pkg/importer/file.go:1
@@ -58,7 +58,7 @@ func GetAvailableSpace(path string) (int64, error) {
 		return int64(-1), err
 	}
 	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	return int64(stat.Bavail) * int64(stat.Bsize), nil //nolint:gosec

shouldn't we tackle this properly instead of nolint? i.e. ensure that both individually and their product does not overflow?

akalenyu akalenyu commented on code on Aug 11, 2026 20:16 UTC
Code Review
pkg/util/util.go:1
@@ -83,7 +83,7 @@ func ParseEnvVar(envVarName string, decode bool) (string, error) {
 // Read reads bytes from the stream and updates the prometheus clone_progress metric according to the progress.
 func (r *CountingReader) Read(p []byte) (n int, err error) {
 	n, err = r.Reader.Read(p)
-	r.Current += uint64(n)
+	r.Current += uint64(n) //nolint:gosec

i think we can avoid the nolint here too by performing checks on n

akalenyu akalenyu commented on Aug 11, 2026 20:16 UTC
Reviewer

thanks! some thoughts plus I think some of the nolints are not needed post your changes, did you try removing them?

kubevirt-bot kubevirt-bot commented on Aug 18, 2026 20:26 UTC
Bot

Pull requests that are marked with lgtm should receive a review
from an approver within 1 week.

After that period the bot marks them with the label needs-approver-review.

/label needs-approver-review

HoustonBoston HoustonBoston commented on code on Aug 21, 2026 17:10 UTC
Code Review
cmd/cdi-controller/controller.go:1
@@ -372,7 +373,7 @@ func main() {
 		klog.Fatalf("Unable to get environment variables: %v\n", errors.WithStack(err))
 	}
 
-	logf.SetLogger(zap.New(zap.Level(zapcore.Level(-1*verbosityLevel)), zap.UseDevMode(debug)))
+	logf.SetLogger(zap.New(zap.Level(zapcore.Level(-1*int8(min(verbosityLevel, math.MaxInt8)))), zap.UseDevMode(debug))) //nolint:gosec // G115: clamped to MaxInt8 above

Yeah, it's pretty bizarre it's still needed

akalenyu akalenyu commented on code on Aug 25, 2026 21:30 UTC
Code Review
pkg/importer/file.go:1
@@ -57,8 +58,18 @@ func GetAvailableSpace(path string) (int64, error) {
 	if err != nil {
 		return int64(-1), err
 	}
-	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	if stat.Bavail > math.MaxInt64 {
+		return math.MaxInt64, nil
+	}
+	avail := int64(stat.Bavail)
+	bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
+	if bsize <= 0 {
+		return 0, nil
+	}
+	if avail > math.MaxInt64/bsize {

this reads a little worse than avail * bsize > maxint, no?

akalenyu akalenyu commented on code on Aug 25, 2026 21:32 UTC
Code Review
pkg/importer/file.go:1
@@ -57,8 +58,18 @@ func GetAvailableSpace(path string) (int64, error) {
 	if err != nil {
 		return int64(-1), err
 	}
-	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	if stat.Bavail > math.MaxInt64 {
+		return math.MaxInt64, nil
+	}
+	avail := int64(stat.Bavail)
+	bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
+	if bsize <= 0 {
+		return 0, nil
+	}
+	if avail > math.MaxInt64/bsize {
+		return math.MaxInt64, nil

I think we should just error out for all those funky cases instead of returning maxint

akalenyu akalenyu commented on code on Aug 25, 2026 21:33 UTC
Code Review
pkg/importer/vddk-datasource_amd64.go:1
@@ -774,33 +769,39 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
 	}
 
 	if extent.Length < 1024*1024 {
+		if extent.Start < 0 || extent.Length < 0 {

does this check not eliminate the need for the nolint below?

akalenyu akalenyu commented on Aug 25, 2026 21:35 UTC
Reviewer

i honestly dont mind keeping nolints on the vddk/imageio data source - mainly curious about nolint being needed. so just file.go comments really🙏

HoustonBoston HoustonBoston commented on code on Aug 25, 2026 22:26 UTC
Code Review
pkg/importer/file.go:1
@@ -57,8 +58,18 @@ func GetAvailableSpace(path string) (int64, error) {
 	if err != nil {
 		return int64(-1), err
 	}
-	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	if stat.Bavail > math.MaxInt64 {
+		return math.MaxInt64, nil
+	}
+	avail := int64(stat.Bavail)
+	bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
+	if bsize <= 0 {
+		return 0, nil
+	}
+	if avail > math.MaxInt64/bsize {
+		return math.MaxInt64, nil

What number should I return and what should the error be?

HoustonBoston HoustonBoston commented on code on Aug 25, 2026 22:28 UTC
Code Review
pkg/importer/file.go:1
@@ -57,8 +58,18 @@ func GetAvailableSpace(path string) (int64, error) {
 	if err != nil {
 		return int64(-1), err
 	}
-	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	if stat.Bavail > math.MaxInt64 {
+		return math.MaxInt64, nil
+	}
+	avail := int64(stat.Bavail)
+	bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
+	if bsize <= 0 {
+		return 0, nil
+	}
+	if avail > math.MaxInt64/bsize {

Doesn't the multiplication cause overflow though?

HoustonBoston HoustonBoston commented on code on Aug 25, 2026 22:34 UTC
Code Review
pkg/importer/vddk-datasource_amd64.go:1
@@ -774,33 +769,39 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
 	}
 
 	if extent.Length < 1024*1024 {
+		if extent.Start < 0 || extent.Length < 0 {

yes it does!

HoustonBoston HoustonBoston commented on Aug 26, 2026 13:48 UTC
Author

/retest-required

akalenyu akalenyu commented on code on Aug 27, 2026 13:07 UTC
Code Review
pkg/importer/file.go:1
@@ -57,8 +58,18 @@ func GetAvailableSpace(path string) (int64, error) {
 	if err != nil {
 		return int64(-1), err
 	}
-	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	if stat.Bavail > math.MaxInt64 {
+		return math.MaxInt64, nil
+	}
+	avail := int64(stat.Bavail)
+	bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
+	if bsize <= 0 {
+		return 0, nil
+	}
+	if avail > math.MaxInt64/bsize {

right

akalenyu akalenyu commented on code on Aug 27, 2026 17:31 UTC
Code Review
pkg/importer/vddk-datasource_amd64.go:1
@@ -730,11 +729,7 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
 
 	// Callback for libnbd.BlockStatus. Needs to modify blocks list above.
 	updateBlocksCallback := func(metacontext string, nbdOffset uint64, extents []uint32, err *int) int {
-		if nbdOffset > math.MaxInt64 {
-			klog.Errorf("Block status offset too big for conversion: 0x%x", nbdOffset)
-			return -2
-		}

I think you need this guard later on when converting back (copyrange)

akalenyu akalenyu commented on code on Aug 27, 2026 17:32 UTC
Code Review
pkg/importer/file.go:1
@@ -57,8 +58,18 @@ func GetAvailableSpace(path string) (int64, error) {
 	if err != nil {
 		return int64(-1), err
 	}
-	//nolint:unconvert
-	return int64(stat.Bavail) * int64(stat.Bsize), nil
+	if stat.Bavail > math.MaxInt64 {
+		return math.MaxInt64, nil
+	}
+	avail := int64(stat.Bavail)
+	bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
+	if bsize <= 0 {
+		return 0, nil
+	}
+	if avail > math.MaxInt64/bsize {
+		return math.MaxInt64, nil

the current revision looks ok to me

HoustonBoston HoustonBoston commented on code on Aug 31, 2026 21:47 UTC
Code Review
pkg/importer/vddk-datasource_amd64.go:1
@@ -730,11 +729,7 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
 
 	// Callback for libnbd.BlockStatus. Needs to modify blocks list above.
 	updateBlocksCallback := func(metacontext string, nbdOffset uint64, extents []uint32, err *int) int {
-		if nbdOffset > math.MaxInt64 {
-			klog.Errorf("Block status offset too big for conversion: 0x%x", nbdOffset)
-			return -2
-		}

Added it back at the end of the function

akalenyu akalenyu commented on code on Sep 01, 2026 11:02 UTC
Code Review
pkg/importer/vddk-datasource_amd64.go:1
@@ -730,11 +729,7 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
 
 	// Callback for libnbd.BlockStatus. Needs to modify blocks list above.
 	updateBlocksCallback := func(metacontext string, nbdOffset uint64, extents []uint32, err *int) int {
-		if nbdOffset > math.MaxInt64 {
-			klog.Errorf("Block status offset too big for conversion: 0x%x", nbdOffset)
-			return -2
-		}

any reason to not check it at the top? before storing?

akalenyu akalenyu commented on Sep 01, 2026 11:04 UTC
Reviewer

/approve

thank you!

akalenyu akalenyu commented on Sep 01, 2026 11:05 UTC
Contributor

/cc @dsanatar

kubevirt-prow[bot] kubevirt-prow[bot] commented on Sep 01, 2026 11:05 UTC
Bot

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: <a href="https://github.com/kubevirt/containerized-data-importer/pull/4193#pullrequestreview-5077200054" title="Approved">akalenyu</a>

The full list of commands accepted by this bot can be found here.

The pull request process is described here

<details >
Needs approval from an approver in each of these files:

  • ~~OWNERS~~ [akalenyu]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    dsanatar dsanatar commented on Sep 02, 2026 14:18 UTC
    Reviewer

    I don't really understand the value of removing the G115 linter exception from the global rule file if we are just going to add the exception back at each impacted line.

    I did some research and apparently for older versions of the golangci-lint package (like the one we are using in cdi) is more strict and produces more false positives for type conversions. I think the linter engine expects these type conversions to occur within the conditional that asserts that the conversion will be safe. I would suggest trying that to see if you can then remove the nolint comments. alternatively, perhaps a package bump could also resolve some of these

    dsanatar dsanatar commented on code on Sep 15, 2026 15:17 UTC
    Code Review
    cmd/cdi-controller/controller.go:1
    @@ -372,7 +373,11 @@ func main() {
     		klog.Fatalf("Unable to get environment variables: %v\n", errors.WithStack(err))
     	}
     
    -	logf.SetLogger(zap.New(zap.Level(zapcore.Level(-1*verbosityLevel)), zap.UseDevMode(debug)))
    +	var level int8
    +	if clampedLevel := min(verbosityLevel, math.MaxInt8); clampedLevel >= 0 && clampedLevel <= math.MaxInt8 {

    do we need to take the minimum here? it makes the second part of the conditional always true. seems like we can drop one of the two.

    also if the the passed in verbosityLevel is negative, this check fails and we default to 0 which is different from the previously defined defVerbose which is 1

    dsanatar dsanatar commented on code on Sep 15, 2026 15:25 UTC
    Code Review
    cmd/cdi-operator/operator.go:1
    @@ -83,7 +84,12 @@ func main() {
     	// implementing the logr.Logger interface. This logger will
     	// be propagated through the whole operator, generating
     	// uniform and structured logs.
    -	logf.SetLogger(zap.New(zap.Level(zapcore.Level(-1*verbosityLevel)), zap.UseDevMode(debug)))
    +	// Note: zapcore.Level is an int8, so we need to convert the verbosityLevel (which has no reason to be an int) to an int8.
    +	var level int8
    +	if clampedLevel := min(verbosityLevel, math.MaxInt8); clampedLevel >= 0 && clampedLevel <= math.MaxInt8 {
    +		level = int8(clampedLevel)

    same comments apply from the controller block

    dsanatar dsanatar commented on code on Sep 15, 2026 15:33 UTC
    Code Review
    pkg/importer/file.go:1
    @@ -57,8 +58,21 @@ func GetAvailableSpace(path string) (int64, error) {
     	if err != nil {
     		return int64(-1), err
     	}
    -	//nolint:unconvert
    -	return int64(stat.Bavail) * int64(stat.Bsize), nil
    +	if stat.Bavail > math.MaxInt64 {
    +		return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)
    +	}
    +	if stat.Bavail <= math.MaxInt64 {

    does it still throw a linting error if we just changed this to an else block since it's the direct inverse of the previous check?

    dsanatar dsanatar commented on code on Sep 15, 2026 15:34 UTC
    Code Review
    pkg/importer/file.go:1
    @@ -57,8 +58,21 @@ func GetAvailableSpace(path string) (int64, error) {
     	if err != nil {
     		return int64(-1), err
     	}
    -	//nolint:unconvert
    -	return int64(stat.Bavail) * int64(stat.Bsize), nil
    +	if stat.Bavail > math.MaxInt64 {
    +		return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)
    +	}
    +	if stat.Bavail <= math.MaxInt64 {
    +		avail := int64(stat.Bavail)
    +		bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform
    +		if bsize <= 0 {
    +			return 0, nil
    +		}
    +		if avail > math.MaxInt64/bsize {
    +			return int64(-1), fmt.Errorf("available space overflow: %d * %d exceeds int64", avail, bsize)
    +		}
    +		return avail * bsize, nil
    +	}
    +	return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)

    this line would never be hit, if it's larger than the max int64 it would be caught in the prior conditional

    dsanatar dsanatar commented on code on Sep 15, 2026 15:36 UTC
    Code Review
    pkg/importer/file.go:1
    @@ -57,8 +58,21 @@ func GetAvailableSpace(path string) (int64, error) {
     	if err != nil {
     		return int64(-1), err
     	}
    -	//nolint:unconvert
    -	return int64(stat.Bavail) * int64(stat.Bsize), nil
    +	if stat.Bavail > math.MaxInt64 {
    +		return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)
    +	}
    +	if stat.Bavail <= math.MaxInt64 {
    +		avail := int64(stat.Bavail)
    +		bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform

    seems like Bsize is already of type int64, do we need this?

    dsanatar dsanatar commented on code on Sep 15, 2026 15:41 UTC
    Code Review
    pkg/importer/imageio-datasource.go:1
    @@ -305,26 +306,42 @@ func (is *ImageioDataSource) StreamExtents(extentsReader *extentReader, fileName
     	// Transfer all the non-zero extents, and try to quickly write out blocks of all zero bytes for extents that only contain zero
     	for index, extent := range extentsReader.extents {
     		if extent.Zero {
    -			err = zeroRange(outFile, extent.Start, extent.Length)
    -			if err != nil {
    -				klog.Infof("Initial zero method failed, trying AppendZeroWithWrite instead. Error was: %v", err)
    -				zeroRange = AppendZeroWithWrite // If the initial choice fails, fall back to regular file writing
    -				err = zeroRange(outFile, extent.Start, extent.Length)
    -				if err != nil {
    -					return errors.Wrap(err, "failed to zero range on destination")
    +			if extent.Start > math.MaxInt64 || extent.Length > math.MaxInt64 {
    +				return errors.New("extent offset or length exceeds maximum int64 size")
    +			}
    +			if extent.Start <= math.MaxInt64 {
    +				if extent.Length <= math.MaxInt64 {

    can this be an else?

    dsanatar dsanatar commented on code on Sep 15, 2026 15:53 UTC
    Code Review
    pkg/importer/imageio-datasource.go:1
    @@ -305,26 +306,42 @@ func (is *ImageioDataSource) StreamExtents(extentsReader *extentReader, fileName
     	// Transfer all the non-zero extents, and try to quickly write out blocks of all zero bytes for extents that only contain zero
     	for index, extent := range extentsReader.extents {
     		if extent.Zero {
    -			err = zeroRange(outFile, extent.Start, extent.Length)
    -			if err != nil {
    -				klog.Infof("Initial zero method failed, trying AppendZeroWithWrite instead. Error was: %v", err)
    -				zeroRange = AppendZeroWithWrite // If the initial choice fails, fall back to regular file writing
    -				err = zeroRange(outFile, extent.Start, extent.Length)
    -				if err != nil {
    -					return errors.Wrap(err, "failed to zero range on destination")
    +			if extent.Start > math.MaxInt64 || extent.Length > math.MaxInt64 {
    +				return errors.New("extent offset or length exceeds maximum int64 size")
    +			}
    +			if extent.Start <= math.MaxInt64 {
    +				if extent.Length <= math.MaxInt64 {
    +					start, length := int64(extent.Start), int64(extent.Length)
    +					err = zeroRange(outFile, start, length)
    +					if err != nil {
    +						klog.Infof("Initial zero method failed, trying AppendZeroWithWrite instead. Error was: %v", err)
    +						zeroRange = AppendZeroWithWrite
    +						err = zeroRange(outFile, start, length)
    +						if err != nil {
    +							return errors.Wrap(err, "failed to zero range on destination")
    +						}
    +					}
     				}
     			}
    -			is.readers.progressReader.Current += uint64(extent.Length)
    +			is.readers.progressReader.Current += extent.Length
     		} else {
     			klog.Infof("Downloading %d-byte extent at offset %d", extent.Length, extent.Start)
    -			responseBody, err := extentsReader.GetRange(extent.Start, extent.Start+extent.Length-1)
    -			if err != nil { // Ignore special EOF case, extents should give the exact right size to read
    -				return errors.Wrap(err, "failed to get range")
    +			endRange := extent.Start + extent.Length - 1
    +			if extent.Start > math.MaxInt64 || endRange > math.MaxInt64 {
    +				return errors.New("extent range exceeds maximum int64 size")
     			}
    -			final := (index == (len(extentsReader.extents) - 1))
    -			err = is.transferExtent(responseBody, outFile, extent, final)
    -			if err != nil {
    -				return errors.Wrap(err, "failed to transfer extent")
    +			if extent.Start <= math.MaxInt64 {
    +				if endRange <= math.MaxInt64 {
    +					responseBody, err := extentsReader.GetRange(int64(extent.Start), int64(endRange))
    +					if err != nil {
    +						return errors.Wrap(err, "failed to get range")
    +					}
    +					final := (index == (len(extentsReader.extents) - 1))
    +					err = is.transferExtent(responseBody, outFile, extent, final)
    +					if err != nil {
    +						return errors.Wrap(err, "failed to transfer extent")
    +					}
    +				}

    is this all even necessary? the fields used to be be int64s before your updates, is there a good reason they should now be uint64s to justify all these extra conditionals just to convert them back into int64s?

    dsanatar dsanatar commented on code on Sep 15, 2026 15:59 UTC
    Code Review
    pkg/importer/vddk-datasource_amd64.go:1
    @@ -712,8 +712,8 @@ type NbdOperations interface {
     
     // BlockStatusData holds zero/hole status for one block of data
     type BlockStatusData struct {
    -	Offset int64
    -	Length int64
    +	Offset uint64
    +	Length uint64
     	Flags  uint32

    also curious about this choice, seems related to my previous comment in imageio-datasource

    dsanatar dsanatar requested changes on Sep 15, 2026 16:14 UTC
    Changes Requested Reviewer

    just have some general questions about some changes you made to certain types in some struct fields but then are seemingly writing guards to allow for converting them back to their original type?

    this should probably get another round of reviews from an approver before it can be merged since there have been a lot of new changes since the prior approval from @awels
    /hold

    HoustonBoston HoustonBoston commented on code on Sep 15, 2026 17:48 UTC
    Code Review
    pkg/importer/file.go:1
    @@ -57,8 +58,21 @@ func GetAvailableSpace(path string) (int64, error) {
     	if err != nil {
     		return int64(-1), err
     	}
    -	//nolint:unconvert
    -	return int64(stat.Bavail) * int64(stat.Bsize), nil
    +	if stat.Bavail > math.MaxInt64 {
    +		return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)
    +	}
    +	if stat.Bavail <= math.MaxInt64 {

    Nope :smile:

    HoustonBoston HoustonBoston commented on code on Sep 15, 2026 17:54 UTC
    Code Review
    pkg/importer/file.go:1
    @@ -57,8 +58,21 @@ func GetAvailableSpace(path string) (int64, error) {
     	if err != nil {
     		return int64(-1), err
     	}
    -	//nolint:unconvert
    -	return int64(stat.Bavail) * int64(stat.Bsize), nil
    +	if stat.Bavail > math.MaxInt64 {
    +		return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)
    +	}
    +	if stat.Bavail <= math.MaxInt64 {
    +		avail := int64(stat.Bavail)
    +		bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform

    Questionable, but AI says it's different on each platform... maybe input from someone who's well-versed with this is required?

    dsanatar dsanatar commented on code on Sep 15, 2026 17:58 UTC
    Code Review
    pkg/importer/file.go:1
    @@ -57,8 +58,21 @@ func GetAvailableSpace(path string) (int64, error) {
     	if err != nil {
     		return int64(-1), err
     	}
    -	//nolint:unconvert
    -	return int64(stat.Bavail) * int64(stat.Bsize), nil
    +	if stat.Bavail > math.MaxInt64 {
    +		return int64(-1), fmt.Errorf("available blocks count %d exceeds int64", stat.Bavail)
    +	}
    +	if stat.Bavail <= math.MaxInt64 {
    +		avail := int64(stat.Bavail)
    +		bsize := int64(stat.Bsize) //nolint:unconvert // type varies by platform

    ah ok I see this is from a golang pkg which does seem to vary by platform, I thought this was a structure we defined.

    dsanatar dsanatar commented on code on Sep 15, 2026 19:42 UTC
    Code Review
    pkg/importer/vddk-datasource_amd64.go:1
    @@ -750,43 +746,58 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
     		}
     		for i := 0; i < len(extents); i += 2 {
     			length, flags := int64(extents[i]), extents[i+1]
    -			if blocks != nil {
    -				last := len(blocks) - 1
    -				lastBlock := blocks[last]
    -				lastFlags := lastBlock.Flags
    -				lastOffset := lastBlock.Offset + lastBlock.Length
    -				if lastFlags == flags && lastOffset == offset {
    -					// Merge with previous block
    -					blocks[last] = &BlockStatusData{
    -						Offset: lastBlock.Offset,
    -						Length: lastBlock.Length + length,
    -						Flags:  lastFlags,
    +			if offset > math.MaxInt64 {
    +				klog.Errorf("Block status offset too big for conversion: 0x%x", offset)
    +				return -2
    +			}

    is there a reason this check and conversion of offset was moved from the beginning of the function? I don't think we need this check for ever iteration of the loop since it won't change

    dsanatar dsanatar commented on code on Sep 15, 2026 19:44 UTC
    Code Review
    pkg/importer/vddk-datasource_amd64.go:1
    @@ -750,43 +746,58 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
     		}
     		for i := 0; i < len(extents); i += 2 {
     			length, flags := int64(extents[i]), extents[i+1]
    -			if blocks != nil {
    -				last := len(blocks) - 1
    -				lastBlock := blocks[last]
    -				lastFlags := lastBlock.Flags
    -				lastOffset := lastBlock.Offset + lastBlock.Length
    -				if lastFlags == flags && lastOffset == offset {
    -					// Merge with previous block
    -					blocks[last] = &BlockStatusData{
    -						Offset: lastBlock.Offset,
    -						Length: lastBlock.Length + length,
    -						Flags:  lastFlags,
    +			if offset > math.MaxInt64 {
    +				klog.Errorf("Block status offset too big for conversion: 0x%x", offset)
    +				return -2
    +			}
    +			if offset <= math.MaxInt64 {
    +				blockOffset := int64(offset)
    +				if blocks != nil {
    +					last := len(blocks) - 1
    +					lastBlock := blocks[last]
    +					lastFlags := lastBlock.Flags
    +					lastOffset := lastBlock.Offset + lastBlock.Length
    +					if lastFlags == flags && lastOffset == blockOffset {
    +						// Merge with previous block
    +						blocks[last] = &BlockStatusData{
    +							Offset: lastBlock.Offset,
    +							Length: lastBlock.Length + length,
    +							Flags:  lastFlags,
    +						}
    +					} else {
    +						blocks = append(blocks, &BlockStatusData{Offset: blockOffset, Length: length, Flags: flags})
     					}
     				} else {
    -					blocks = append(blocks, &BlockStatusData{Offset: offset, Length: length, Flags: flags})
    +					blocks = append(blocks, &BlockStatusData{Offset: blockOffset, Length: length, Flags: flags})
     				}
    -			} else {
    -				blocks = append(blocks, &BlockStatusData{Offset: offset, Length: length, Flags: flags})
     			}
    -			offset += length
    +			if length >= 0 {
    +				offset += uint64(length)

    if u leave convert the offset value at the beginning, you can remove this check and conversion for length

    dsanatar dsanatar commented on code on Sep 15, 2026 19:45 UTC
    Code Review
    pkg/importer/vddk-datasource_amd64.go:1
    @@ -750,43 +746,58 @@ func GetBlockStatus(handle NbdOperations, extent types.DiskChangeExtent) []*Bloc
     		}
     		for i := 0; i < len(extents); i += 2 {
     			length, flags := int64(extents[i]), extents[i+1]
    -			if blocks != nil {
    -				last := len(blocks) - 1
    -				lastBlock := blocks[last]
    -				lastFlags := lastBlock.Flags
    -				lastOffset := lastBlock.Offset + lastBlock.Length
    -				if lastFlags == flags && lastOffset == offset {
    -					// Merge with previous block
    -					blocks[last] = &BlockStatusData{
    -						Offset: lastBlock.Offset,
    -						Length: lastBlock.Length + length,
    -						Flags:  lastFlags,
    +			if offset > math.MaxInt64 {
    +				klog.Errorf("Block status offset too big for conversion: 0x%x", offset)
    +				return -2
    +			}
    +			if offset <= math.MaxInt64 {
    +				blockOffset := int64(offset)
    +				if blocks != nil {
    +					last := len(blocks) - 1
    +					lastBlock := blocks[last]
    +					lastFlags := lastBlock.Flags
    +					lastOffset := lastBlock.Offset + lastBlock.Length
    +					if lastFlags == flags && lastOffset == blockOffset {
    +						// Merge with previous block
    +						blocks[last] = &BlockStatusData{
    +							Offset: lastBlock.Offset,
    +							Length: lastBlock.Length + length,
    +							Flags:  lastFlags,
    +						}
    +					} else {
    +						blocks = append(blocks, &BlockStatusData{Offset: blockOffset, Length: length, Flags: flags})
     					}
     				} else {
    -					blocks = append(blocks, &BlockStatusData{Offset: offset, Length: length, Flags: flags})
    +					blocks = append(blocks, &BlockStatusData{Offset: blockOffset, Length: length, Flags: flags})
     				}
    -			} else {
    -				blocks = append(blocks, &BlockStatusData{Offset: offset, Length: length, Flags: flags})
     			}
    -			offset += length
    +			if length >= 0 {
    +				offset += uint64(length)
    +			}
     		}
     		return 0
     	}
     
     	if extent.Length < 1024*1024 {
    +		if extent.Start < 0 || extent.Length < 0 {
    +			return nil
    +		}

    do we need this guard if we aren't doing any type conversion?

    dsanatar dsanatar commented on code on Sep 15, 2026 19:47 UTC
    Code Review
    pkg/importer/vddk-datasource_amd64.go:1
    @@ -1353,25 +1385,31 @@ func (vs *VDDKDataSource) TransferFile(fileName string, preallocation bool) (Pro
     			}
     		}
     	} else { // Cold migration full copy
    -		start := uint64(0)
    -		blocksize := uint64(MaxBlockStatusLength)
    -		for i := start; i < vs.Size; i += blocksize {
    -			if (vs.Size - i) < blocksize {
    -				blocksize = vs.Size - i
    -			}
    +		diskSize := vs.Size
    +		if diskSize > math.MaxInt64 {
    +			return ProcessingPhaseError, fmt.Errorf("disk size %d exceeds int64", diskSize)
    +		}
    +		if diskSize <= math.MaxInt64 {

    change to else?

    dsanatar dsanatar commented on Sep 15, 2026 19:49 UTC
    Reviewer

    looks a lot cleaner, just some extra things I noticed

    HoustonBoston HoustonBoston commented on Sep 21, 2026 21:19 UTC
    Author

    /retest-required

    HoustonBoston HoustonBoston commented on Sep 24, 2026 14:02 UTC
    Author

    /unhold

    kubevirt-prow[bot] kubevirt-prow[bot] commented on Sep 30, 2026 21:35 UTC
    Bot

    @HoustonBoston: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

    Test name | Commit | Details | Required | Rerun command
    --- | --- | --- | --- | ---
    pull-containerized-data-importer-e2e-s390x | 81a97e68675dcaeea0b88b667c7a57a50adabbd9 | link | false | /test pull-containerized-data-importer-e2e-s390x

    <details>

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.
    </details>
    <!-- test report -->

    dsanatar dsanatar approved these changes on Oct 01, 2026 13:04 UTC
    Approved Reviewer

    Approved these changes.

    kubevirt-bot kubevirt-bot commented on Oct 01, 2026 15:29 UTC
    Bot

    /remove-label needs-approver-review

    Reviewers
    Assignees
    HoustonBoston HoustonBoston
    Labels
    risk: low confidence: 74.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 74.7% · Lower = rushed or shallow review
    74.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.2% · Safe to merge
    12.2%