Extend bytebuffer for relation payloads

Change-Id: I128c64d6f8e1ac3148d3d603d20552cab2882821
diff --git a/Changes b/Changes
index 263becf..6a6b75d 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 0.55.9 2017-09-12
         - [bugfix] Serialize token identifier correctly for
           new corpora with text siglen (diewald)
+        - [bugfix] Extend bytebuffer for relation payloads (diewald)
 
 0.55.8 2017-09-05
         - [feature] Retrieve and display pagebreaks (diewald)
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index b7f735a..2066932 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -138,7 +138,7 @@
 
     private byte[] pl = new byte[4];
     private static ByteBuffer bb = ByteBuffer.allocate(4),
-            bbOffset = ByteBuffer.allocate(8), bbTerm = ByteBuffer.allocate(16);
+            bbOffset = ByteBuffer.allocate(8), bbTerm = ByteBuffer.allocate(32);
 
     // Some initializations ...
     {
@@ -1182,7 +1182,8 @@
 
                             // Copy the payload
                             bbTerm.clear();
-                            if (payload != null) {
+
+                            if (payload != null && payload.length <= bbTerm.capacity()) {
                                 bbTerm.put(payload.bytes, payload.offset,
                                         payload.length);
                             };
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java
index eb08591..ae57732 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java
@@ -249,5 +249,15 @@
 		assertEquals(km.getSnippetBrackets(), "... [[{malt/d:DET>132567:meine} {#132567:{malt/d:ATTR>132567:eigne}} {malt/d:PN>132564:Erfahrung}]] ...");
 		assertEquals(km.getSnippetHTML(), "<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\"><mark><span xlink:title=\"malt/d:DET\" xlink:type=\"simple\" xlink:href=\"#token-GOE/AGD/00000-p132567\">meine</span> <span xml:id=\"token-GOE/AGD/00000-p132567\"><span xlink:title=\"malt/d:ATTR\" xlink:type=\"simple\" xlink:href=\"#token-GOE/AGD/00000-p132567\">eigne</span></span> <span xlink:title=\"malt/d:PN\" xlink:type=\"simple\" xlink:href=\"#token-GOE/AGD/00000-p132564\">Erfahrung</span></mark></span><span class=\"context-right\"><span class=\"more\"></span></span>");
 
+		km = sample.getMatchInfo("match-GOE/AGD/00000-p132566-132569",
+								 "tokens",
+								 "malt",
+								 "d",
+								 true,
+								 true,
+								 true);
+
+		assertEquals(km.getSnippetBrackets().substring(0,20), "[{#132507:{malt/d:SU");
+		assertEquals(km.getSnippetHTML().substring(0,20), "<span class=\"context");
 	}   
 }