From 959bf4a7f47bbad6541b3762dc1f6aa19be48403 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 24 Jan 2010 02:11:55 +0000 Subject: [PATCH] limit max graph size --- .../java/src/net/i2p/router/web/GraphHelper.java | 9 ++++++--- .../java/src/net/i2p/router/web/StatSummarizer.java | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/GraphHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/GraphHelper.java index ede694f1d4..2d676bdacf 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/GraphHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/GraphHelper.java @@ -25,6 +25,9 @@ public class GraphHelper extends HelperBase { private static final int DEFAULT_Y = 100; private static final int DEFAULT_REFRESH = 60; private static final int DEFAULT_PERIODS = 60; + static final int MAX_X = 2048; + static final int MAX_Y = 1024; + private static final int MIN_REFRESH = 15; public GraphHelper() { } @@ -45,13 +48,13 @@ public class GraphHelper extends HelperBase { } public void setShowEvents(boolean b) { _showEvents = b; } public void setHeight(String str) { - try { _height = Integer.parseInt(str); } catch (NumberFormatException nfe) {} + try { _height = Math.min(Integer.parseInt(str), MAX_Y); } catch (NumberFormatException nfe) {} } public void setWidth(String str) { - try { _width = Integer.parseInt(str); } catch (NumberFormatException nfe) {} + try { _width = Math.min(Integer.parseInt(str), MAX_X); } catch (NumberFormatException nfe) {} } public void setRefreshDelay(String str) { - try { _refreshDelaySeconds = Integer.parseInt(str); } catch (NumberFormatException nfe) {} + try { _refreshDelaySeconds = Math.max(Integer.parseInt(str), MIN_REFRESH); } catch (NumberFormatException nfe) {} } public String getImages() { diff --git a/apps/routerconsole/java/src/net/i2p/router/web/StatSummarizer.java b/apps/routerconsole/java/src/net/i2p/router/web/StatSummarizer.java index 4b29475a1c..15232fbcc8 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/StatSummarizer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/StatSummarizer.java @@ -119,6 +119,10 @@ public class StatSummarizer implements Runnable { return renderPng(rate, out, -1, -1, false, false, false, false, -1, true); } public boolean renderPng(Rate rate, OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents, int periodCount, boolean showCredit) throws IOException { + if (width > GraphHelper.MAX_X) + width = GraphHelper.MAX_X; + if (height > GraphHelper.MAX_Y) + height = GraphHelper.MAX_Y; for (int i = 0; i < _listeners.size(); i++) { SummaryListener lsnr = (SummaryListener)_listeners.get(i); if (lsnr.getRate().equals(rate)) { @@ -147,6 +151,10 @@ public class StatSummarizer implements Runnable { public boolean renderRatePng(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid, boolean hideTitle, boolean showEvents, int periodCount, boolean showCredit) throws IOException { long end = _context.clock().now() - 60*1000; + if (width > GraphHelper.MAX_X) + width = GraphHelper.MAX_X; + if (height > GraphHelper.MAX_Y) + height = GraphHelper.MAX_Y; if (periodCount <= 0) periodCount = SummaryListener.PERIODS; if (periodCount > SummaryListener.PERIODS) periodCount = SummaryListener.PERIODS; -- GitLab