From a341781aa419d9b6eec105dc8a5d59ff52138e41 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 15 Apr 2008 02:49:03 +0000 Subject: [PATCH] put entry validation inline with entry reading git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@326 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../healthmarketscience/jackcess/Index.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 9eb3ca1..ec3629d 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -806,6 +806,7 @@ public abstract class Index implements Comparable { TempBufferHolder.newHolder(TempBufferHolder.Type.HARD, true, ByteOrder.BIG_ENDIAN); + Entry prevEntry = FIRST_ENTRY; for (int i = 0; i < entryMaskLength; i++) { byte entryMask = buffer.get(entryMaskPos + i); for (int j = 0; j < 8; j++) { @@ -823,8 +824,14 @@ public abstract class Index implements Comparable { curEntryLen += entryPrefix.length; } totalEntrySize += curEntryLen; + + Entry entry = newEntry(curEntryBuffer, curEntryLen, isLeaf); + if(prevEntry.compareTo(entry) >= 0) { + throw new IOException("Unexpected order in index entries, " + + prevEntry + " >= " + entry); + } - entries.add(newEntry(curEntryBuffer, curEntryLen, isLeaf)); + entries.add(entry); if(entries.size() == 1) { if(entryPrefixLength > 0) { @@ -836,19 +843,10 @@ public abstract class Index implements Comparable { } lastStart += length; + prevEntry = entry; } } } - - // check the entry order, just to be safe - for(int i = 0; i < (entries.size() - 1); ++i) { - Entry e1 = entries.get(i); - Entry e2 = entries.get(i + 1); - if(e1.compareTo(e2) > 0) { - throw new IOException("Unexpected order in index entries, " + - e1 + " is greater than " + e2); - } - } dataPage.setEntryPrefix(entryPrefix != null ? entryPrefix : EMPTY_PREFIX); dataPage.setEntries(entries); -- 2.39.5