Skip to content

Commit fa1523a

Browse files
committed
PHPLIB-245: Require chunkSizeBytes to be a positive integer
1 parent 21f8624 commit fa1523a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/GridFS/Bucket.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public function __construct(Manager $manager, $databaseName, array $options = []
8080
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
8181
}
8282

83+
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
84+
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
85+
}
86+
8387
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
8488
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
8589
}

src/GridFS/WritableStream.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
6767
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
6868
}
6969

70+
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
71+
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
72+
}
73+
7074
if (isset($options['contentType']) && ! is_string($options['contentType'])) {
7175
throw InvalidArgumentException::invalidType('"contentType" option', $options['contentType'], 'string');
7276
}

tests/GridFS/BucketFunctionalTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public function provideInvalidConstructorOptions()
6868
return $options;
6969
}
7070

71+
/**
72+
* @expectedException MongoDB\Exception\InvalidArgumentException
73+
* @expectedExceptionMessage Expected "chunkSizeBytes" option to be >= 1, 0 given
74+
*/
75+
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive()
76+
{
77+
new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 0]);
78+
}
79+
7180
/**
7281
* @dataProvider provideInputDataAndExpectedChunks
7382
*/

tests/GridFS/WritableStreamFunctionalTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ public function provideInvalidConstructorOptions()
5252
return $options;
5353
}
5454

55+
/**
56+
* @expectedException MongoDB\Exception\InvalidArgumentException
57+
* @expectedExceptionMessage Expected "chunkSizeBytes" option to be >= 1, 0 given
58+
*/
59+
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive()
60+
{
61+
new WritableStream($this->collectionWrapper, 'filename', ['chunkSizeBytes' => 0]);
62+
}
63+
5564
/**
5665
* @dataProvider provideInputDataAndExpectedMD5
5766
*/

0 commit comments

Comments
 (0)