<!-- Don't forget to update status.xml too! -->
<release version="3.2-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out</action>
<action dev="POI-DEVELOPERS" type="add">45844 - Addtional diagnostics for HSLF SlideShowRecordDumper</action>
<action dev="POI-DEVELOPERS" type="fix">45829 - HSSFPicture.getImageDimension() failed when DPI of image is zero</action>
<action dev="POI-DEVELOPERS" type="fix">45815 - Bit mask values in StyleTextPropAtom were not preserved across read-write</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.2-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out</action>
<action dev="POI-DEVELOPERS" type="add">45844 - Addtional diagnostics for HSLF SlideShowRecordDumper</action>
<action dev="POI-DEVELOPERS" type="fix">45829 - HSSFPicture.getImageDimension() failed when DPI of image is zero</action>
<action dev="POI-DEVELOPERS" type="fix">45815 - Bit mask values in StyleTextPropAtom were not preserved across read-write</action>
field_4_footer = footer;
field_3_unicode_flag =
(byte) (StringUtil.hasMultibyte(field_4_footer) ? 1 : 0);
+ // Check it'll fit into the space in the record
+
+ if(field_4_footer == null) return;
+ if(field_3_unicode_flag == 1) {
+ if(field_4_footer.length() > 127) {
+ throw new IllegalArgumentException("Footer string too long (limit is 127 for unicode strings)");
+ }
+ } else {
+ if(field_4_footer.length() > 255) {
+ throw new IllegalArgumentException("Footer string too long (limit is 255 for non-unicode strings)");
+ }
+ }
}
/**
field_4_header = header;
field_3_unicode_flag =
(byte) (StringUtil.hasMultibyte(field_4_header) ? 1 : 0);
+
+ // Check it'll fit into the space in the record
+ if(field_4_header == null) return;
+ if(field_3_unicode_flag == 1) {
+ if(field_4_header.length() > 127) {
+ throw new IllegalArgumentException("Header string too long (limit is 127 for unicode strings)");
+ }
+ } else {
+ if(field_4_header.length() > 255) {
+ throw new IllegalArgumentException("Header string too long (limit is 255 for non-unicode strings)");
+ }
+ }
}
/**
assertFalse(nwb.isSheetHidden(2));
assertTrue(nwb.isSheetVeryHidden(2));
}
+
+ /**
+ * header / footer text too long
+ */
+ public void test45777() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet s = wb.createSheet();
+
+ String s248 = "";
+ for(int i=0; i<248; i++) {
+ s248 += "x";
+ }
+ String s249 = s248 + "1";
+ String s250 = s248 + "12";
+ String s251 = s248 + "123";
+ assertEquals(248, s248.length());
+ assertEquals(249, s249.length());
+ assertEquals(250, s250.length());
+ assertEquals(251, s251.length());
+
+
+ // Try on headers
+ s.getHeader().setCenter(s248);
+ assertEquals(254, s.getHeader().getRawHeader().length());
+ writeOutAndReadBack(wb);
+
+ s.getHeader().setCenter(s249);
+ assertEquals(255, s.getHeader().getRawHeader().length());
+ writeOutAndReadBack(wb);
+
+ try {
+ s.getHeader().setCenter(s250); // 256
+ fail();
+ } catch(IllegalArgumentException e) {}
+
+ try {
+ s.getHeader().setCenter(s251); // 257
+ fail();
+ } catch(IllegalArgumentException e) {}
+
+
+ // Now try on footers
+ s.getFooter().setCenter(s248);
+ assertEquals(254, s.getFooter().getRawFooter().length());
+ writeOutAndReadBack(wb);
+
+ s.getFooter().setCenter(s249);
+ assertEquals(255, s.getFooter().getRawFooter().length());
+ writeOutAndReadBack(wb);
+
+ try {
+ s.getFooter().setCenter(s250); // 256
+ fail();
+ } catch(IllegalArgumentException e) {}
+
+ try {
+ s.getFooter().setCenter(s251); // 257
+ fail();
+ } catch(IllegalArgumentException e) {}
+ }
}