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

internal/graph: Support comments with double quotes #688

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

evanj
Copy link
Contributor

@evanj evanj commented Mar 10, 2022

The first comment in a pprof file is used as the subgraph ID for the
legend, but was not escaped. If the comment contained double quotes,
it could cause graphviz to fail to parse the output, or to render
incorrect graphs. To reproduce, run the following commands:

$ pprof -add_comment "unterminated \"double quote" -proto -output=bug.pprof in.pprof
Generating report in labels-no-specials-unterminated-double-quote.pprof
$ pprof -comments bug.pprof
unterminated "double quote
$ pprof -web bug.pprof
Error: <stdin>: syntax error in line 3 near '\'
pprof: failed to execute dot. Is Graphviz installed? Error: exit status 1

Add a test for this case. Without the change to dotgraph.go, the test
produced the following dot output:

digraph "testtitle" {
node [style=filled fillcolor="#f8f8f8"]
subgraph cluster_L { "comment line 1
comment line 2 "unterminated double quote" [shape=box fontsize=16 label="comment line 1\lcomment line 2 \"unterminated double quote\lsecond comment \"double quote\"\l" tooltip="testtitle"] }
N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" id="node1" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"]
N2 [label="dest\n15 (15.00%)\nof 25 (25.00%)" id="node2" fontsize=24 shape=box tooltip="dest (25)" color="#b23c00" fillcolor="#edddd5"]
N1 -> N2 [label=" 10" weight=11 color="#b28559" tooltip="src -> dest (10)" labeltooltip="src -> dest (10)"]
}

This failed to parse with dot:

$ dot ./internal/graph/testdata/compose9.dot
Error: ./internal/graph/testdata/compose9.dot: syntax error in line 4 near '\'

After adding the escaping, the test case now parses with dot, and the
new test case works as expected.

The output for this test case is the following:

Screen Shot 2022-03-10 at 10 46 37 AM

The first comment in a pprof file is used as the subgraph ID for the
legend, but was not escaped. If the comment contained double quotes,
it could cause graphviz to fail to parse the output, or to render
incorrect graphs. To reproduce, run the following commands:

$ pprof -add_comment "unterminated \"double quote" -proto -output=bug.pprof in.pprof
Generating report in labels-no-specials-unterminated-double-quote.pprof
$ pprof -comments bug.pprof
unterminated "double quote
$ pprof -web bug.pprof
Error: <stdin>: syntax error in line 3 near '\'
pprof: failed to execute dot. Is Graphviz installed? Error: exit status 1

Add a test for this case. Without the change to dotgraph.go, the test
produced the following dot output:

digraph "testtitle" {
node [style=filled fillcolor="#f8f8f8"]
subgraph cluster_L { "comment line 1
comment line 2 "unterminated double quote" [shape=box fontsize=16 label="comment line 1\lcomment line 2 \"unterminated double quote\lsecond comment \"double quote\"\l" tooltip="testtitle"] }
N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" id="node1" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"]
N2 [label="dest\n15 (15.00%)\nof 25 (25.00%)" id="node2" fontsize=24 shape=box tooltip="dest (25)" color="#b23c00" fillcolor="#edddd5"]
N1 -> N2 [label=" 10" weight=11 color="#b28559" tooltip="src -> dest (10)" labeltooltip="src -> dest (10)"]
}

This failed to parse with dot:

$ dot ./internal/graph/testdata/compose9.dot
Error: ./internal/graph/testdata/compose9.dot: syntax error in line 4 near '\'

After adding the escaping, the test case now parses with dot, and the
new test case works as expected.
@aalexand aalexand merged commit 5bba342 into google:master Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants