Skip to content

Commit

Permalink
Carve out more nuisances.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Jan 26, 2018
1 parent b6f5979 commit da67a28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Stream/MutableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ public function readBytes(int $num, bool $skipTests = false): string
} elseif ($num === 0) {
return '';
}
// @codeCoverageIgnoreEnd
if (($this->pos + $num) > $this->stat['size']) {
throw new CannotPerformOperation('Out-of-bounds read');
}
// @codeCoverageIgnoreEnd
$buf = '';
$remaining = $num;
do {
Expand Down Expand Up @@ -250,9 +250,11 @@ public function writeBytes(string $buf, int $num = null): int
// @codeCoverageIgnoreEnd
$remaining = $num;
do {
// @codeCoverageIgnoreStart
if ($remaining <= 0) {
break;
}
// @codeCoverageIgnoreEnd
$written = \fwrite($this->fp, $buf, $remaining);
if ($written === false) {
// @codeCoverageIgnoreStart
Expand Down
6 changes: 4 additions & 2 deletions src/Stream/ReadOnlyFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function getSize(): int
*/
public function readBytes(int $num, bool $skipTests = false): string
{
// @codeCoverageIgnoreStart
if ($num < 0) {
throw new CannotPerformOperation('num < 0');
} elseif ($num === 0) {
Expand All @@ -219,16 +220,17 @@ public function readBytes(int $num, bool $skipTests = false): string
throw new CannotPerformOperation('Out-of-bounds read');
}
$buf = '';
// @codeCoverageIgnoreEnd
$remaining = $num;
if (!$skipTests) {
$this->toctouTest();
}
do {
// @codeCoverageIgnoreStart
if ($remaining <= 0) {
// @codeCoverageIgnoreStart
break;
// @codeCoverageIgnoreEnd
}
// @codeCoverageIgnoreEnd
/** @var string $read */
$read = \fread($this->fp, $remaining);
if (!\is_string($read)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Symmetric/Crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ public static function decryptWithAd(

// Check the MAC first
if (!self::verifyMAC(
// @codeCoverageIgnoreStart
(string) $auth,
(string) $version .
(string) $salt .
(string) $nonce .
(string) $additionalData .
(string) $encrypted,
// @codeCoverageIgnoreEnd
$authKey,
$config
)) {
Expand Down

0 comments on commit da67a28

Please sign in to comment.