Bug 65839 - The resize method takes INFINITY, causing an infinite loop
Summary: The resize method takes INFINITY, causing an infinite loop
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 5.2.0-FINAL
Hardware: PC Mac OS X 10.1
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-24 03:13 UTC by currycheng
Modified: 2022-02-21 17:33 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description currycheng 2022-01-24 03:13:14 UTC
When the image is damaged, the length and width value of the image is 0, and the scale may change to INFINITY during calculation, causing the program to loop endlessly

package org.apache.poi.hssf.usermodel;    
@Override
    public void resize(double scaleX, double scaleY) {
        HSSFClientAnchor anchor = getClientAnchor();
        anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);

        HSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);

        int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1());
        int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());

        anchor.setCol2((short)col2);
        // anchor.setDx1(0);
        anchor.setDx2(pref.getDx2());

        anchor.setRow2(row2);
        // anchor.setDy1(0);
        anchor.setDy2(pref.getDy2());
    }
Comment 1 PJ Fanning 2022-01-24 09:53:43 UTC
I added r1897406 as a starting point
Comment 2 PJ Fanning 2022-01-24 17:33:19 UTC
We might want to consider setting a max number of iterations in ImageUtils.setPreferredSize