Skip to content

revisit explorer#630

Draft
patricios-space wants to merge 3 commits intomainfrom
explorer/revisit
Draft

revisit explorer#630
patricios-space wants to merge 3 commits intomainfrom
explorer/revisit

Conversation

@patricios-space
Copy link
Collaborator

@patricios-space patricios-space commented Feb 26, 2026

Features

  • Mermaid trace now opens url in browser automatically
  • Any tx hash in a trace will return whole trace

Bug Fixes

  • adnl timeout error. fixed with retry

TODO

  • make it more user friendly
  • connect with cld

return nil, fmt.Errorf("failed to parse shard from toncenter response: %w", err)
}

block, err := api.LookupBlock(ctx, res.BlockRef.Workchain, int64(shard), res.BlockRef.SeqNo)

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 int64 without an upper bound check.

Copilot Autofix

AI about 1 hour ago

In general, to fix this class of issues you must ensure that any integer parsed with a larger bit size is not converted to a smaller signed type without verifying that the value lies within the target type’s range. For strconv.ParseUint(..., 64) feeding into int64, you must ensure the parsed value is <= math.MaxInt64 before doing int64(value). If the value is out of range, you should treat it as an error (or clamp/ignore it, depending on your application’s semantics).

For this specific case in pkg/ton/codec/debug/explorer/explorer.go, the best fix with minimal behavior change is:

  • Import the math package (it is not currently imported in this file).
  • After successfully parsing shard with strconv.ParseUint, add a bounds check ensuring shard <= math.MaxInt64.
  • If the check fails, return an error indicating the shard value is out of range.
  • Only then perform the cast int64(shard) for the call to api.LookupBlock.

Concretely:

  • Update the import block at the top of explorer.go to add "math".
  • In findTxByToncenterMetadata, between the strconv.ParseUint call and api.LookupBlock, insert a check:
    if shard > math.MaxInt64 {
        return nil, fmt.Errorf("shard value out of range for int64: %d", shard)
    }
  • Leave the rest of the function as is, but now the conversion int64(shard) is guaranteed safe.
Suggested changeset 1
pkg/ton/codec/debug/explorer/explorer.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/pkg/ton/codec/debug/explorer/explorer.go b/pkg/ton/codec/debug/explorer/explorer.go
--- a/pkg/ton/codec/debug/explorer/explorer.go
+++ b/pkg/ton/codec/debug/explorer/explorer.go
@@ -7,6 +7,7 @@
 	"encoding/json"
 	"errors"
 	"fmt"
+	"math"
 	"net/http"
 	"net/url"
 	"os/exec"
@@ -698,6 +699,9 @@
 	if err != nil {
 		return nil, fmt.Errorf("failed to parse shard from toncenter response: %w", err)
 	}
+	if shard > math.MaxInt64 {
+		return nil, fmt.Errorf("shard value out of range for int64: %d", shard)
+	}
 
 	block, err := api.LookupBlock(ctx, res.BlockRef.Workchain, int64(shard), res.BlockRef.SeqNo)
 	if err != nil {
EOF
@@ -7,6 +7,7 @@
"encoding/json"
"errors"
"fmt"
"math"
"net/http"
"net/url"
"os/exec"
@@ -698,6 +699,9 @@
if err != nil {
return nil, fmt.Errorf("failed to parse shard from toncenter response: %w", err)
}
if shard > math.MaxInt64 {
return nil, fmt.Errorf("shard value out of range for int64: %d", shard)
}

block, err := api.LookupBlock(ctx, res.BlockRef.Workchain, int64(shard), res.BlockRef.SeqNo)
if err != nil {
Copilot is powered by AI and may make mistakes. Always verify output.
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