Event stream decoder reports a checksum mismatch when the checksum is read in parts

クローズ
#3,371 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@stobrien89 がすでに取り組んでいます。

2026年10月17日 から。

  • #3373 @lazerg による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
php
領域
api

調査の方向性

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 の本文から書いたものです。

説明

bug investigating p2

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws/aws-sdk-php のほかの issue

aws/aws-sdk-php の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。