fish2018/pansou · error

空响应无法去填充

Error message

空响应无法去填充

What it means

removeMobilePadding in the mobile check crypto path rejects an empty ciphertext buffer before attempting to strip custom padding. It guards the last-byte padding-size read; an empty payload means decryption produced nothing usable or the caller passed nil/empty data.

Solutions

  1. Validate the encrypted payload is non-empty before decrypting (len(payload) > 0 and a multiple of the block size).
  2. Check why decryptMobilePayload produced empty output — log payload length at each stage.
  3. Fix upstream to return the HTTP error body instead of an empty response.

Example fix

// before
plain, err := decryptMobilePayload(respBody, key)
// after
if len(respBody) == 0 {
    return fmt.Errorf("empty payload")
}
plain, err := decryptMobilePayload(respBody, key)
Defensive patterns

Strategy: validation

Validate before calling

if len(payload) == 0 || len(payload)%aes.BlockSize != 0 {
    return fmt.Errorf("bad payload length: %d", len(payload))
}

Try / catch

plain, err := removeMobilePadding(data)
if err != nil {
    return fmt.Errorf("payload undecryptable: %w", err)
}

Prevention

When it happens

Trigger: decryptMobilePayload calls removeMobilePadding with a zero-length byte slice — the decrypted output was empty because the upstream response body was empty or AES decryption silently produced no data.

Common situations: Server returned HTTP 200 with an empty body; a decryption step failed upstream and returned an empty slice instead of an error; wrong key/IV causing a zeroed pipeline result.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07). Data as JSON: /api/errors/5e3458242ffde542. Report an issue: GitHub.

Appendix: source

Thrown at service/check_mobile_crypto.go:104

			}
			return raw, nil
		}
		return nil, fmt.Errorf("不支持的请求类型: %T", value)
	}
}

func addMobilePadding(data []byte, blockSize int) []byte {
	paddingSize := blockSize - len(data)%blockSize
	padding := make([]byte, paddingSize)
	for index := range padding {
		padding[index] = byte(paddingSize)
	}
	return append(data, padding...)
}

func removeMobilePadding(data []byte) ([]byte, error) {
	if len(data) == 0 {
		return nil, fmt.Errorf("空响应无法去填充")
	}

	paddingSize := int(data[len(data)-1])
	if paddingSize <= 0 || paddingSize > len(data) {
		return nil, fmt.Errorf("填充长度非法")
	}

	for index := len(data) - paddingSize; index < len(data); index++ {
		if data[index] != byte(paddingSize) {
			return nil, fmt.Errorf("填充校验失败")
		}
	}

	return data[:len(data)-paddingSize], nil
}

View on GitHub (pinned to beaa561337)