fix: panic under some stupid input config

This commit is contained in:
wwqgtxx
2025-04-09 17:53:36 +08:00
parent 4b15568a29
commit 487d7fa81f
2 changed files with 12 additions and 5 deletions

View File

@@ -50,7 +50,11 @@ func (c Config) Build() (*Builder, error) {
realityConfig.ShortIds = make(map[[8]byte]bool)
for i, shortIDString := range c.ShortID {
var shortID [8]byte
decodedLen, err := hex.Decode(shortID[:], []byte(shortIDString))
decodedLen := hex.DecodedLen(len(shortIDString))
if decodedLen > 8 {
return nil, fmt.Errorf("invalid short_id[%d]: %s", i, shortIDString)
}
decodedLen, err = hex.Decode(shortID[:], []byte(shortIDString))
if err != nil {
return nil, fmt.Errorf("decode short_id[%d] '%s': %w", i, shortIDString, err)
}