Skip to content

varbin: Fix handle private field by accident#95

Merged
nekohasekai merged 1 commit intoSagerNet:devfrom
xchacha20-poly1305:patch-2
Jan 27, 2026
Merged

varbin: Fix handle private field by accident#95
nekohasekai merged 1 commit intoSagerNet:devfrom
xchacha20-poly1305:patch-2

Conversation

@xchacha20-poly1305
Copy link
Contributor

  • If a field named _, CanSet() returns false.
  • Or (||) operation skips CanSet() check, causing panic.

@xchacha20-poly1305
Copy link
Contributor Author

Another bug:

Write incorrectly applies reflect.Indirect to the input rawData before passing it to the internal write function. This causes a panic when a nil pointer is passed because reflect.Indirect returns an invalid reflect.Value, and the subsequent error handling path attempts to call .String() on a nil type.

Furthermore, stripping the pointer type at the top level causes the encoder to bypass the pointer-handling logic that writes a presence marker (0 or 1). Because the Read function expects this marker to determine if it should allocate memory, the lack of this byte causes a protocol mismatch, leading to data corruption or decoding failures.

Trying to fix this may breaks the protocol behavior, so I will not create a pull request to fix it.

@nekohasekai
Copy link
Member

The *reflect portion of the varbin package appears to only include the following use cases:

  1. geodb related code in sing-box that hasn't been completely removed.

  2. libbox serialization in sing-box 1.12 (now replaced by gRPC).

Its original purpose was to prevent problems with manually written libbox serialization, but it seems to have many bugs, and I believe we can safely remove this package soon.

@nekohasekai nekohasekai merged commit 0494030 into SagerNet:dev Jan 27, 2026
6 of 7 checks passed
@nekohasekai
Copy link
Member

I apologize for informing you that I am reverting your two fix commits because I pushed them to the sing-box stable branch without verifying compatibility, and they caused production breakage.

Since I will be removing the use of varbin serialization in 1.13, and 1.13 will soon be the new stable release, I also reverted them in sing dev for compatibility testing.

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.

2 participants