Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable13] Make sure the file is readable before attempting to create a preview #9668

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public function __construct(
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
*/
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
//Make sure that we can read the file
if (!$file->isReadable()) {
throw new NotFoundException('Cannot read file');
}


$this->eventDispatcher->dispatch(
IPreview::EVENT,
new GenericEvent($file,[
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/Preview/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public function setUp() {

public function testGetCachedPreview() {
$file = $this->createMock(File::class);
$file->method('isReadable')
->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
Expand Down Expand Up @@ -122,6 +124,8 @@ public function testGetCachedPreview() {

public function testGetNewPreview() {
$file = $this->createMock(File::class);
$file->method('isReadable')
->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
Expand Down Expand Up @@ -248,6 +252,8 @@ public function testInvalidMimeType() {
$this->expectException(NotFoundException::class);

$file = $this->createMock(File::class);
$file->method('isReadable')
->willReturn(true);

$this->previewManager->method('isMimeSupported')
->with('invalidType')
Expand All @@ -271,6 +277,8 @@ public function testInvalidMimeType() {

public function testNoProvider() {
$file = $this->createMock(File::class);
$file->method('isReadable')
->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
Expand Down Expand Up @@ -350,6 +358,8 @@ public function dataSize() {
*/
public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expectedX, $expectedY) {
$file = $this->createMock(File::class);
$file->method('isReadable')
->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
Expand Down Expand Up @@ -416,4 +426,14 @@ public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expec
$this->assertSame($preview, $result);
}
}

public function testUnreadbleFile() {
$file = $this->createMock(File::class);
$file->method('isReadable')
->willReturn(false);

$this->expectException(NotFoundException::class);

$this->generator->getPreview($file, 100, 100, false);
}
}