Event stream decoder reports a checksum mismatch when the checksum is read in parts
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
The bug is in NonSeekableStreamDecodingEventStreamIterator, where the trailing four-byte checksum is read with a single read(4) call before comparison. Check how the existing partial-read handling for headers and payload works, then make the checksum read loop until it has four bytes or the stream ends. Done when the reproduction script no longer throws and a partial-read test with one-byte reads passes. Pull request #3373 is already open against this issue, so review it first.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
NonSeekableStreamDecodingEventStreamIterator rejects a valid event when the stream returns its trailing checksum in more than one read.
The decoder handles partial reads for the headers and payload, but reads the four checksum bytes with a single read(4) call. A stream can return fewer bytes even when more data is still coming.
Expected Behavior
I think the decoder should keep reading until it has all four checksum bytes, or reaches the end of the stream.
Current Behavior
The example below throws:
Aws\Api\Parser\Exception\ParserException: Message checksum mismatch.
The frame has a valid checksum. It parses successfully when the read limit is removed.
Reproduction Steps
This example doesn’t need an AWS account or make any network requests.
Install aws/aws-sdk-php version 3.399.2, then run:
<?php
require 'vendor/autoload.php';
use Aws\Api\Parser\NonSeekableStreamDecodingEventStreamIterator;
use GuzzleHttp\Psr7\FnStream;
use GuzzleHttp\Psr7\NoSeekStream;
use GuzzleHttp\Psr7\Utils;
$headers = '';
foreach ([
':message-type' => 'event',
':event-type' => 'messageStop',
':content-type' => 'application/json',
] as $name => $value) {
$headers .= chr(strlen($name)).$name.chr(7)
.pack('n', strlen($value)).$value;
}
$payload = '{"stopReason":"end_turn"}';
$prelude = pack('NN', 16 + strlen($headers) + strlen($payload), strlen($headers));
$frame = $prelude.hash('crc32b', $prelude, true).$headers.$payload;
$frame .= hash('crc32b', $frame, true);
$body = Utils::streamFor($frame);
$stream = new NoSeekStream(FnStream::decorate($body, [
'read' => static fn ($length) => $body->read(min(1, $length)),
]));
$iterator = new NonSeekableStreamDecodingEventStreamIterator($stream);
$iterator->rewind();
Possible Solution
Read the complete trailing checksum before comparing it. The existing partial-read test could also include reads limited to one byte.
Additional Information/Context
This appears to be a missed case from #3165, which fixed partial reads for #3110. Its test limits reads to 20 bytes, so the four-byte checksum still arrives in one read.
I also reproduced this with a local HTTP server that sends the checksum in two parts. The same single checksum read is still present on master.
SDK version used
3.399.2
Environment details
PHP 8.4.25, Ubuntu 24.04.
Generated by Codex, and reviewed by @binaryfire.
- 主要言語
- PHP
- スター
- 6.2k
- フォーク
- 1.3k
- 平均マージ
- 4日 15時間
- マージ済み PR(30日)
- 22
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws/aws-sdk-php のほかの issue
-
bug p2 queued service-api
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
aws/aws-sdk-php#3395 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
RDS auth tokens and presigned URLs get an expiry one hour too long during the autumn DST change対応中かも @stobrien89 が 6 日前に担当しました。 オープンbug
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
aws/aws-sdk-php#3392 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
The SDK now requires PHP 8.2 or later対応中かも @stobrien89 が 16 日前に担当しました。 オープンannouncement SECURITY
aws/aws-sdk-php#3385 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Shared config file is read and parsed repeatedly when creating a client対応中かも @LukaszFilipowski が 6 日前に担当しました。 オープンfeature-request p3
難易度 3/5 半日 初心者へのやさしさ 45/100
aws/aws-sdk-php#3377 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
announcement
難易度 4/5 3〜5日 初心者へのやさしさ 12/100
aws/aws-sdk-php#3369 ·
メンテナーはふだん 1 日以内に返信
aws/aws-sdk-php の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 79/100
smarty-php/smarty#1220 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
opnsense/core#11171 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
getgrav/grav-plugin-form#664 ·
-
claude
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sprain/sprainocchio#26 ·
-
sync-en
難易度 1/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信