From 8a9622c31cbd8e05b9da0bc448b729594fffd299 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 24 May 2015 01:59:40 +0200 Subject: [PATCH] fix string OoB on getImagelinks with long alttext in description calculation --- source/net/yacy/document/Document.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/net/yacy/document/Document.java b/source/net/yacy/document/Document.java index 8d2524957..cc69970ac 100644 --- a/source/net/yacy/document/Document.java +++ b/source/net/yacy/document/Document.java @@ -1003,10 +1003,18 @@ dc_rights if (tagname.length() > 0) { if (sb.length() > Request.descrLength - tagname.length() - 3) { // cut this off because otherwise the tagname is lost. - sb.setLength(Request.descrLength - tagname.length() - 3); + if (tagname.length() > Request.descrLength) { // but in rare case tagname could be extreme long + sb.setLength(0); + sb.append(tagname.substring(0, Request.descrLength)); + } else { + sb.setLength(Request.descrLength - tagname.length()); + sb.append(" - "); + sb.append(tagname); + } + } else { + sb.append(" - "); + sb.append(tagname); } - sb.append(" - "); - sb.append(tagname); } return sb.toString().trim(); }