Skip to content

[pad] adjust image saving in web canvas - #24225

Open
linev wants to merge 2 commits into
root-project:masterfrom
linev:webcanv_saveimage
Open

linev wants to merge 2 commits into
root-project:masterfrom
linev:webcanv_saveimage

Conversation

@linev

@linev linev commented Nov 18, 2026

Copy link
Copy Markdown
Member

TPad::Print() method used to generate images.
It had explicit handling of web canvas with its own log output.
And there was drawback in case when C macro was produced - while TCanvas::Update() also was invoked for web canvas

Now move code in one central place where image generation via pad painter interface is handled.
And use normal TPad::Print logging when generate image also for web canvas case.
Also remove misleading warning about unsupported C file format in web canvas.

Comment thread graf2d/gpad/src/TPad.cxx

//==============Save pad/canvas as a HTML==============================
if (gtype == TImage::kHtml) {
auto cmd = TString::Format("TWebCanvas::ProduceImage((TPad *) 0x%zx, \"%s\");", (size_t) this, psname.Data());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should find a different way to do this. What if psname is a maliciously-crafted string like "\"); gSystem->Exec(\"rm -rf $HOME\");" ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, one can create small plugin for this. I need to think

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use regex here to exclude all special symbols - before writing any special plugin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpiparo thoughs about this? I'm personally always skeptical about this kind of sanitization...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of sanitization was discussed in the past. I think the conclusion is that it could seem that it guarantees security, while, on the other hand, it's hard to guarantee it does.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not change code which was existing - just moved it and add regex to filter-out "dangerous" symbols.
One can do it better - but this will invoke plugin handler - which potentially has more problems while using much more sophisticated interpreter.

This code will be significantly changed by transition to ROOT7.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 11h 22m 9s ⏱️
 3 893 tests  3 892 ✅ 0 💤 1 ❌
76 208 runs  76 207 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit 7c64f36.

♻️ This comment has been updated with latest results.

Finalize changes of SaveAs logic in the pad/canvas - there is now
the only place where pad painter SaveAsImage is called for all kinds of painters,
no special call for web canvas in the front.

Only difference for web - discard border highlight before saving.
Therefore there is no need to call Update() for the web canvas.
Now information printed from TPad::Print() method.
Old log messages can be enabled with gDebug = 1
@linev
linev force-pushed the webcanv_saveimage branch from e5b4a28 to 7c64f36 Compare November 19, 2026 13:16
@linev
linev requested a review from silverweed November 19, 2026 13:16
@linev

linev commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@silverweed

I decide to suppress default logging from RWebDisplayHandle::ProduceImages() method, only when gDebug > 0.
There is normal Info printout now for all kinds of generated files

For HTML file creation I using regex to remove any kind of extra symbols.

@silverweed
silverweed requested a review from dpiparo November 19, 2026 13:52

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants