diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f22c5d4..a0f27bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ All notable changes to this project will be documented in this file, in reverse While malformed addresses should never reach this class, this extra hardening helps ensure safety in cases where a developer codes their own `AddressInterface` implementations for these types of addresses. +- [#141](https://github.com/zendframework/zend-mail/pull/141) updates + `Zend\Mail\Message::getHeaders()` to throw an exception in a case where the + `$headers` property is not a `Headers` instance. ### Deprecated diff --git a/src/Storage/Part.php b/src/Storage/Part.php index 3e75dee7..a860e96e 100644 --- a/src/Storage/Part.php +++ b/src/Storage/Part.php @@ -266,6 +266,7 @@ public function countParts() * Lazy-loads if not already attached. * * @return Headers + * @throws Exception\RuntimeException */ public function getHeaders() { @@ -277,6 +278,11 @@ public function getHeaders() $this->headers = new Headers(); } } + if (! $this->headers instanceof Headers) { + throw new Exception\RuntimeException( + '$this->headers must be an instance of Headers' + ); + } return $this->headers; } diff --git a/test/Storage/MessageTest.php b/test/Storage/MessageTest.php index 6c731fe8..b012f4f0 100644 --- a/test/Storage/MessageTest.php +++ b/test/Storage/MessageTest.php @@ -276,6 +276,18 @@ public function testEmptyHeader() $this->setExpectedException('Zend\\Mail\\Exception\\InvalidArgumentException'); $message->subject; } + + public function testWrongHeaderType() + { + // @codingStandardsIgnoreStart + $badMessage = unserialize( + "O:25:\"Zend\Mail\Storage\Message\":9:{s:8:\"\x00*\x00flags\";a:0:{}s:10:\"\x00*\x00headers\";s:16:\"Yellow submarine\";s:10:\"\x00*\x00content\";N;s:11:\"\x00*\x00topLines\";s:0:\"\";s:8:\"\x00*\x00parts\";a:0:{}s:13:\"\x00*\x00countParts\";N;s:15:\"\x00*\x00iterationPos\";i:1;s:7:\"\x00*\x00mail\";N;s:13:\"\x00*\x00messageNum\";i:0;}" + ); + // @codingStandardsIgnoreEnd + + $this->setExpectedException(MailException\RuntimeException::class); + $badMessage->getHeaders(); + } public function testEmptyBody() {