Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/driver/gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,22 @@ public function renderToOutput()
*/
public function render( $file )
{
// Path traversal guard: resolve the destination directory and verify
// it exists and is reachable without escaping via '..' sequences.
if ( $file !== null )
{
if ( strpos( $file, "\0" ) !== false )
{
throw new ezcBaseValueException( 'file', $file, 'a valid filesystem path (no null bytes)' );
}
$dir = realpath( dirname( $file ) );
if ( $dir === false )
{
throw new ezcBaseFileNotFoundException( dirname( $file ), 'directory' );
}
$file = $dir . DIRECTORY_SEPARATOR . basename( $file );
}

$destination = imagecreatetruecolor( $this->options->width, $this->options->height );

// Default to a transparent white background
Expand Down
15 changes: 14 additions & 1 deletion src/driver/svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,12 +1266,25 @@ public function renderToOutput()
*/
public function render( $file )
{
// Path traversal guard: resolve the destination directory and verify
// it exists and is reachable without escaping via '..' sequences.
if ( strpos( $file, "\0" ) !== false )
{
throw new ezcBaseValueException( 'file', $file, 'a valid filesystem path (no null bytes)' );
}
$dir = realpath( dirname( $file ) );
if ( $dir === false )
{
throw new ezcBaseFileNotFoundException( dirname( $file ), 'directory' );
}
$safeFile = $dir . DIRECTORY_SEPARATOR . basename( $file );

$this->createDocument();
$this->drawAllTexts();

// Embed used glyphs
$this->font->addFontToDocument( $this->dom );
$this->dom->save( $file );
$this->dom->save( $safeFile );
}

/**
Expand Down