Skip to content

Fix plaintext length check for UTF-8 strings#193

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-utf8-length-check
Draft

Fix plaintext length check for UTF-8 strings#193
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-utf8-length-check

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented May 23, 2026

What

Use byte length instead of character length in check_max_message_length().

Why

sv_len() returns character count for UTF-8-flagged SVs, but rsa_crypt() passes raw bytes to OpenSSL via SvPV(). When a UTF-8 string has multi-byte characters, the byte count exceeds the character count — so the pre-validation could pass while OpenSSL rejects the oversized input with a generic error instead of the descriptive "plaintext too long" message.

How

Changed check_max_message_length() to accept SV* directly and extract byte length via SvPV(), matching what rsa_crypt() actually sends to OpenSSL. Both encrypt() and private_encrypt() callers updated.

Testing

  • Added test in t/crypto.t: constructs a UTF-8 string where character count (120) < OAEP max (214) but byte count (240) > OAEP max, verifying the descriptive error fires.
  • Full test suite passes (669 tests).

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 26 insertions(+), 4 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

check_max_message_length() used sv_len() which returns character count
for UTF-8 SVs, but rsa_crypt() passes the raw bytes to OpenSSL via
SvPV().  For multi-byte UTF-8 strings the byte count exceeds the
character count, so the pre-validation could pass while OpenSSL rejects
the oversized input with a generic error instead of our descriptive
"plaintext too long" message.

Switch check_max_message_length() to accept the SV directly and extract
byte length via SvPV(), matching what rsa_crypt() actually sends to
OpenSSL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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