fish2018/pansou · error
无效的加密区间
Error message
无效的加密区间 %d:%d
What it means
encryptPayload validates config.Start/End against a 24-byte random token length and fails with '无效的加密区间 %d:%d' when the range is invalid: Start < 0, End <= Start, or End > len(no) (24). This is a configuration validation error inside the plugin, not a network issue.
Solutions
- Inspect the apiConfig values for Start/End in your config and ensure 0 <= Start < End <= 24
- Remember End indexes the 24-byte random token (randomToken(24)), not the payload; cap End at 24
- Fix negative or swapped Start/End values (End must be strictly greater than Start)
- Validate config at load time with the same predicate used in encryptPayload
Example fix
// before Start: 0, End: 32 // after Start: 0, End: 24 // End must satisfy 0 <= Start < End <= 24
Defensive patterns
Strategy: validation
Validate before calling
if cfg.Start < 0 || cfg.End <= cfg.Start || cfg.End > 24 {
return fmt.Errorf("无效的加密区间 %d:%d", cfg.Start, cfg.End)
} Type guard
func validRange(start, end int) bool { return start >= 0 && end > start && end <= 24 } Try / catch
payload, err := encryptPayload(p, cfg)
if err != nil {
if strings.Contains(err.Error(), "无效的加密区间") {
return fmt.Errorf("配置错误: start/end 必须满足 0 <= start < end <= 24: %w", err)
}
return err
} Prevention
- Validate Start/End when loading the plugin config, before any request
- Remember the range indexes randomToken(24), so End must never exceed 24
- Treat End as an exclusive-style bound strictly greater than Start
- Add a unit test covering the boundary values 0, 24, and swapped ranges
When it happens
Trigger: A yingso apiConfig has Start negative, End less than or equal to Start, or End greater than 24 (the fixed random token length), passed via search or resolveItem.
Common situations: Mis-edited config file with wrong start/end offsets; config copied from another plugin with a different token size; assumptions that End indexes a payload field rather than the 24-byte token; off-by-one treating End as inclusive index into a 0..23 slice.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/211250f6035b44cc.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/yingso/yingso.go:330
if len(data) > maxResponseSize {
return fmt.Errorf("响应超过 %d 字节", maxResponseSize)
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(data)))
}
if err := jsonutil.Unmarshal(data, target); err != nil {
return fmt.Errorf("解析响应失败: %w", err)
}
return nil
}
func encryptPayload(payload interface{}, config apiConfig) (encryptedPayload, error) {
no, err := randomToken(24)
if err != nil {
return encryptedPayload{}, err
}
if config.Start < 0 || config.End <= config.Start || config.End > len(no) {
return encryptedPayload{}, fmt.Errorf("无效的加密区间 %d:%d", config.Start, config.End)
}
encoded, err := jsonutil.MarshalString(payload)
if err != nil {
return encryptedPayload{}, err
}
return encryptedPayload{
No: no,
Info: xorUTF16(encoded, no[config.Start:config.End]),
}, nil
}
func randomToken(length int) (string, error) {
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
data := make([]byte, length)
if _, err := rand.Read(data); err != nil {
return "", err
}View on GitHub (pinned to beaa561337)