Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F803580
InsecureRemarkupGraphvizBlockInterpreter.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
epriestley
Sep 13 2015, 7:17 PM
2015-09-13 19:17:23 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
InsecureRemarkupGraphvizBlockInterpreter.php
View Options
<?php
/**
* !!! WARNING !!!
*
* This rule is NOT SECURE! It contains KNOWN VULNERABILITIES which permit an
* attacker to (at a minimum) disclose information about the system with a
* specially crafted input.
*
* INSTALL THIS RULE AT YOUR OWN RISK.
*/
final
class
InsecureRemarkupGraphvizBlockInterpreter
extends
PhutilRemarkupBlockInterpreter
{
public
function
getInterpreterName
()
{
return
'dot'
;
}
public
function
markupContent
(
$content
,
array
$argv
)
{
if
(!
Filesystem
::
binaryExists
(
'dot'
))
{
return
$this
->
markupError
(
pht
(
'Unable to locate the `%s` binary. Install Graphviz.'
,
'dot'
));
}
$width
=
$this
->
parseDimension
(
idx
(
$argv
,
'width'
));
$future
=
id
(
new
ExecFuture
(
'dot -T%s'
,
'png'
))
->
setTimeout
(
15
)
->
write
(
trim
(
$content
));
list
(
$err
,
$stdout
,
$stderr
)
=
$future
->
resolve
();
if
(
$err
)
{
return
$this
->
markupError
(
pht
(
'Execution of `%s` failed (#%d), check your syntax: %s'
,
'dot'
,
$err
,
$stderr
));
}
$file
=
PhabricatorFile
::
buildFromFileDataOrHash
(
$stdout
,
array
(
'name'
=>
'graphviz.png'
,
));
if
(
$this
->
getEngine
()->
isTextMode
())
{
return
'<'
.
$file
->
getBestURI
().
'>'
;
}
$img
=
phutil_tag
(
'img'
,
array
(
'src'
=>
$file
->
getBestURI
(),
'width'
=>
nonempty
(
$width
,
null
),
));
return
phutil_tag_div
(
'phabricator-remarkup-embed-image-full'
,
$img
);
}
// TODO: This is duplicated from PhabricatorEmbedFileRemarkupRule since they
// do not share a base class.
private
function
parseDimension
(
$string
)
{
$string
=
trim
(
$string
);
if
(
preg_match
(
'/^(?:
\d
*
\\
.)?
\d
+%?$/'
,
$string
))
{
return
$string
;
}
return
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/x5/pt/ctnvfcykvfifxlq7
Default Alt Text
InsecureRemarkupGraphvizBlockInterpreter.php (1 KB)
Attached To
Mode
P1853 InsecureRemarkupGraphvizBlockInterpreter.php
Attached
Detach File
Event Timeline
Log In to Comment