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

RRDtool can generate errors to standard output which can corrupt images #2930

Closed
ibatten opened this issue Sep 9, 2019 · 6 comments
Closed
Labels
bug Undesired behaviour resolved A fixed issue
Milestone

Comments

@ibatten
Copy link

ibatten commented Sep 9, 2019

Describe the bug

Graphs of type SVG do not render; graphs of type PNG render correctly.

To Reproduce

Edit between SVG and PNG in Graph Templates; the graphs can be switched between rendering and producing an error.

Expected behavior

Graphs should render as they did on 1.2.5. Only change to system is switch from 1.2.5 to 1.2.6.

Screenshots

I have flicked everything to PNG other than the "Load Average" template. Once this is done, only the Load Average template fails to render.

Desktop (please complete the following information):

MacOS 10.14.6, latest Safari bits, latest Chrome bits (all unchanged since 1.2.5 was working).

Smartphone (please complete the following information):

n/a

Additional context

RRDtool 1.7.2 Copyright by Tobias Oetiker tobi@oetiker.ch
Compiled May 30 2019 23:12:11

The SVG file appears superficially correct: I have clicked "Save Image" from the broken image, and then opened the resulting SVG file with both Chrome and Safari, and it renders. However, it throws a warning:

"This page contains the following errors:

error on line 930 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error."

Looking at the saved SVG file, line 930 with cat -n is very suggestive:

924
925
926
927
928
929
930 OK u:0.03 s:0.00 r:0.02ians-macbook-air:Downloads igb$

The same has happened to the PNG files, but presumably PNG renderers are less fussy about stray characters:

ians-macbook-air:Downloads igb$ od -c cacti_graph_118.png | tail
0143120 7 227 307 あ ** ** 035 320 \a 201 374 \a \0 232 ! 024
0143140 \n ' M 232 d 354 U 364 017 270 \ 356 333 o 277 m
0143160 354 U \0 \0 9 360 371 037 \0 \0 \0 212 @ 376 003 0143200 \0 \0 \0 L 021 310 177 \0 \0 \0 200 ) 002 371 017 \0 0143220 \0 \0 0 E 8 g Μ ** 251 254 254 4 366 2 \0 \0 0143240 \0 \0 240 W 371 ? o $ 353 g 034 262 353 } \0 \0 0143260 \0 \0 I E N D 256 B 202 O K u : 0
0143300 . 0 5 s : 0 . 0 1 r : 0 . 0
0143320 5
0143321
ians-macbook-air:Downloads igb$

So it looks like a change has been made which causes part of the diagnostic calculations to be appended to images, which is accepted by PNG renders but not SVG renderers.

The problem can be localised to lib/rrd.php; I have replaced the 1.2.6 version with that taken from 1.2.5 and it fixes the problem. I then tried each patch in turn, and the problem is triggered by the changes in 14 lines starting at 289 which go from popen()ing the rrdtool command with the arguments on the command line, to popen()ing the rrdtool command reading from stdin and then passing the command in that way. I assume this somehow triggers different behaviour deeper in the code, which I do not have the skills to trace through. I am now running with the 1.2.6 lib/rrd.php but with the section from line 289 onwards replaced with the previous code from 1.2.5.

In summary: 1.2.6: does not render SVG. 1.2.6+ lib/rrd.php from 1.2.5: OK. Frankenstein version of 1.2.5 lib/rrd.php with the new code from line 289 onwards replaced with the corresponding code from 1.2.5: OK. And for confirmation, "cat -n | tail -2" on a saved version of one of the SVG graphs it now generates does not have the trailing CPU usage message.

@ibatten ibatten changed the title 1.2.6: incorrect SVG generation 1.2.6: lib/rrd.php changes around line 289 cause SVG mis-rendering, plus partial fix. Sep 10, 2019
@cigamit
Copy link
Member

cigamit commented Sep 10, 2019

Good to know. What OS platform? Yea, and interesting. Looks like stderr is being redirected into stdout.

@cigamit cigamit added the bug Undesired behaviour label Sep 10, 2019
@ibatten
Copy link
Author

ibatten commented Sep 10, 2019 via email

@cigamit cigamit changed the title 1.2.6: lib/rrd.php changes around line 289 cause SVG mis-rendering, plus partial fix. When working in pipe mode RRDtool appends stderr to stdout causing SVG graphing to break Sep 11, 2019
cigamit added a commit that referenced this issue Sep 11, 2019
* When working in pipe mode RRDtool appends stderr to stdout causing SVG graphing to break
* Remove GIF87 as it's no longer supported
cigamit added a commit that referenced this issue Sep 11, 2019
cigamit added a commit that referenced this issue Sep 11, 2019
* When working in pipe mode RRDtool appends stderr to stdout causing SVG graphing to break
* Removing GIF87 as it's no longer supported
* Adding new Trim function
@cigamit cigamit added the resolved A fixed issue label Sep 11, 2019
@cigamit
Copy link
Member

cigamit commented Sep 11, 2019

This should be resolved now. Please update lib/rrd.php and verify.

@ibatten
Copy link
Author

ibatten commented Sep 11, 2019 via email

cigamit added a commit that referenced this issue Sep 11, 2019
This will speed up the function.
@interduo
Copy link
Contributor

interduo commented Sep 12, 2019

In branch 1.2.x

2019/09/12 16:11:54 - CMDPHP PHP ERROR WARNING Backtrace: (/graph_image.php[132]:rrdtool_function_graph(), /lib/rrd.php[2271]:rrdtool_execute(), /lib/rrd.php[242]:__rrd_execute(), /lib/rrd.php[359]:rrdtool_trim_output(), /lib/rrd.php[406]:strpos(), CactiErrorHandler())
--
2019/09/12 16:11:54 - ERROR PHP WARNING: strpos(): Offset not contained in string in file: /var/www/html/cacti/lib/rrd.php on line: 406
2019/09/12 16:11:46 - CMDPHP PHP ERROR WARNING Backtrace: (/graph_image.php[132]:rrdtool_function_graph(), /lib/rrd.php[2271]:rrdtool_execute(), /lib/rrd.php[242]:__rrd_execute(), /lib/rrd.php[359]:rrdtool_trim_output(), /lib/rrd.php[406]:strpos(), CactiErrorHandler())
2019/09/12 16:11:46 - ERROR PHP WARNING: strpos(): Offset not contained in string in file: /var/www/html/cacti/lib/rrd.php on line: 406
2019/09/12 16:11:38 - CMDPHP PHP ERROR WARNING Backtrace: (/graph_json.php[158]:rrdtool_function_graph(), /lib/rrd.php[2271]:rrdtool_execute(), /lib/rrd.php[242]:__rrd_execute(), /lib/rrd.php[359]:rrdtool_trim_output(), /lib/rrd.php[406]:strpos(), CactiErrorHandler())
2019/09/12 16:11:38 - ERROR PHP WARNING: strpos(): Offset not contained in string in file: /var/www/html/cacti/lib/rrd.php on line: 406
2019/09/12 16:11:38 - CMDPHP PHP ERROR WARNING Backtrace: (/graph_json.php[158]:rrdtool_function_graph(), /lib/rrd.php[2271]:rrdtool_execute(), /lib/rrd.php[242]:__rrd_execute(), /lib/rrd.php[359]:rrdtool_trim_output(), /lib/rrd.php[406]:strpos(), CactiErrorHandler())
2019/09/12 16:11:38 - ERROR PHP WARNING: strpos(): Offset not contained in string in file: /var/www/html/cacti/lib/rrd.php on line: 406
2019/09/12 16:11:38 - CMDPHP PHP ERROR WARNING Backtrace: (/graph_json.php[158]:rrdtool_function_graph(), /lib/rrd.php[2271]:rrdtool_execute(), /lib/rrd.php[242]:__rrd_execute(), /lib/rrd.php[359]:rrdtool_trim_output(), /lib/rrd.php[406]:strpos(), CactiErrorHandler())
2019/09/12 16:11:38 - ERROR PHP WARNING: strpos(): Offset not contained in string in file: /var/www/html/cacti/lib/rrd.php on line: 406
2019/09/12 16:11:38 - CMDPHP PHP ERROR WARNING Backtrace: (/graph_json.php[158]:rrdtool_function_graph(), /lib/rrd.php[2271]:rrdtool_execute(), /lib/rrd.php[242]:__rrd_execute(), /lib/rrd.php[359]:rrdtool_trim_output(), /lib/rrd.php[406]:strpos(), CactiErrorHandler())
2019/09/12 16:11:38 - ERROR PHP WARNING: strpos(): Offset not contained in string in file: /var/www/html/cacti/lib/rrd.php on line: 406

In the apache2 log:
[Thu Sep 12 16:11:54.558485 2019] [:error] [pid 13903] [client 172.20.2.42:43892] PHP Warning: strpos(): Offset not contained in string in /var/www/html/cacti/lib/rrd.php on line 406, referer: https://cacti/plugins/thold/thold.php?action=edit&id=815

@ibatten
Copy link
Author

ibatten commented Sep 12, 2019 via email

cigamit added a commit that referenced this issue Sep 15, 2019
The function was actually not working.  So, using a function that searches from the end, and passing by reference to for an additional speedup.
@cigamit cigamit added this to the v1.2.7 milestone Sep 15, 2019
@cigamit cigamit closed this as completed Sep 15, 2019
@netniV netniV changed the title When working in pipe mode RRDtool appends stderr to stdout causing SVG graphing to break RRDtool can generate errors to standard output which can corrupt images Sep 28, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

3 participants