Anomaly identified by the detector. Please review whether this anomaly corresponds to a misuse.
Finding:
1
In File:
com/itextpdf/text/pdf/PdfReader.java
In Method:
selectPages(List)
Code with Finding:
class PdfReader {
/**
* Selects the pages to keep in the document. The pages are described as a
* <CODE>List</CODE> of <CODE>Integer</CODE>. The page ordering can be changed but
* no page repetitions are allowed. Note that it may be very slow in partial mode.
* @param pagesToKeep the pages to keep in the document
*/
public void selectPages(final List<Integer> pagesToKeep) {
pageRefs.selectPages(pagesToKeep);
removeUnusedObjects();
}
}
class PdfReader.PageRefs {
private void selectPages(final List<Integer> pagesToKeep) {
IntHashtable pg = new IntHashtable();
ArrayList<Integer> finalPages = new ArrayList<Integer>();
int psize = size();
for (Integer pi : pagesToKeep) {
int p = pi.intValue();
if (p >= 1 && p <= psize && pg.put(p, 1) == 0)
finalPages.add(pi);
}
if (reader.partial) {
for (int k = 1; k <= psize; ++k) {
getPageOrigRef(k);
resetReleasePage();
}
}
PRIndirectReference parent = (PRIndirectReference)reader.catalog.get(PdfName.PAGES);
PdfDictionary topPages = (PdfDictionary)PdfReader.getPdfObject(parent);
ArrayList<PRIndirectReference> newPageRefs = new ArrayList<PRIndirectReference>(finalPages.size());
PdfArray kids = new PdfArray();
for (int k = 0; k < finalPages.size(); ++k) {
int p = finalPages.get(k).intValue();
PRIndirectReference pref = getPageOrigRef(p);
resetReleasePage();
kids.add(pref);
newPageRefs.add(pref);
getPageN(p).put(PdfName.PARENT, parent);
}
AcroFields af = reader.getAcroFields();
boolean removeFields = af.getFields().size() > 0;
for (int k = 1; k <= psize; ++k) {
if (!pg.containsKey(k)) {
if (removeFields)
af.removeFieldsFromPage(k);
PRIndirectReference pref = getPageOrigRef(k);
int nref = pref.getNumber();
reader.xrefObj.set(nref, null);
if (reader.partial) {
reader.xref[nref * 2] = -1;
reader.xref[nref * 2 + 1] = 0;
}
}
}
topPages.put(PdfName.COUNT, new PdfNumber(finalPages.size()));
topPages.put(PdfName.KIDS, kids);
refsp = null;
refsn = newPageRefs;
}
}