Bug 58443 - [PATCH] Corrupted workbook: sheet contains overlapping merged regions
Summary: [PATCH] Corrupted workbook: sheet contains overlapping merged regions
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
: 58070 (view as bug list)
Depends on: 58350
Blocks: 59740
  Show dependency tree
 
Reported: 2015-09-22 03:39 UTC by Javen O'Neal
Modified: 2016-06-22 18:30 UTC (History)
1 user (show)



Attachments
patch to check for intersection when adding a merged region (13.37 KB, patch)
2015-09-22 03:47 UTC, Javen O'Neal
Details | Diff
patch to check for intersection when adding a merged region (13.28 KB, patch)
2015-09-22 03:51 UTC, Javen O'Neal
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Javen O'Neal 2015-09-22 03:39:25 UTC
It's currently possible in POI to create a spreadsheet with overlapping merged regions. When saved to a file, this results in a corrupted workbook that Microsoft Excel must repair before being able to read.

In order to eliminate the possibility of creating a corrupted workbook from merged regions, Sheet.addMergedRegion(CellRangeAddress) should check existing merged regions for any existing regions that overlap with the candidate.
Comment 1 Javen O'Neal 2015-09-22 03:47:23 UTC
Created attachment 33128 [details]
patch to check for intersection when adding a merged region

Fixes:
* remove HSSFSheet.addMergedRegion(Region), which has been deprecated since Aug 2008
* modified H/XSSFSheet.addMergedRegion to check if candidate region overlaps with an existing region, and throw an IllegalStateException if there is overlap, and corresponding unit test
* add CellRangeAddressBase.intersects and corresponding unit test
* fixed several unit tests that unintentionally created overlapping merged regions.

Note: this patch requires the fix for bug 58350 (attachment 33086 [details]).
Comment 2 Javen O'Neal 2015-09-22 03:51:03 UTC
Created attachment 33129 [details]
patch to check for intersection when adding a merged region

fixed whitespace
Comment 3 Javen O'Neal 2015-09-23 14:19:48 UTC
Current implementation runs in linear time to add one merged region, and quadratic time if adding multiple regions. Is there a faster way (O(n log n)?) to add multiple regions? If so, we may want to add a addMergedRegions(List<CellRangeAddress>) if users plan on adding many merged regions.
Comment 4 Javen O'Neal 2015-10-31 10:39:33 UTC
Applied to trunk in r1711581 and r1711586:
* prevent corrupted workbooks by checking for overlapping merged regions before adding a merged region to a sheet
* fix unit tests that produced corrupt workbooks due to overlapping merged regions
* remove deprecated HSSFSheet#addMergedRegion(Region)

Documentation updated in r1711590.
Comment 5 Javen O'Neal 2015-12-29 06:08:12 UTC
*** Bug 58070 has been marked as a duplicate of this bug. ***
Comment 6 David North 2016-01-18 14:44:04 UTC
Spun performance regression off as bug 58885