From 44b2ba7fdbfffe928b5d26baa0733ff019e6740c Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 7 Mar 2008 19:23:46 +0000 Subject: [PATCH] Fix bug caused by sign extension when reading single-byte row numbers; fix some bugs in new text index generation code git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@252 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 3 +++ src/java/com/healthmarketscience/jackcess/Column.java | 4 ++-- src/java/com/healthmarketscience/jackcess/Index.java | 6 ++++-- .../com/healthmarketscience/jackcess/PageChannel.java | 6 ++++-- src/java/com/healthmarketscience/jackcess/Table.java | 8 +++++--- src/java/com/healthmarketscience/jackcess/UsageMap.java | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4b1add1..767da5f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -18,6 +18,9 @@ Expand the characters supported in index updates to all of the ISO-8859-1 character set. + + Fix bug caused by sign extension when reading single-byte row numbers. + diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 6f05cea..1912787 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -451,7 +451,7 @@ public class Column implements Comparable { lvalDefinition.length); } - byte rowNum = def.get(); + int rowNum = ByteUtil.toUnsignedInt(def.get()); int pageNum = ByteUtil.get3ByteInt(def, def.position()); ByteBuffer lvalPage = getPageChannel().createPageBuffer(); @@ -485,7 +485,7 @@ public class Column implements Comparable { // read next page information lvalPage.position(rowStart); - rowNum = lvalPage.get(); + rowNum = ByteUtil.toUnsignedInt(lvalPage.get()); pageNum = ByteUtil.get3ByteInt(lvalPage); // update rowEnd and remainingLen based on chunkLength diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 2a46959..eb57194 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -948,6 +948,7 @@ public class Index implements Comparable { ++charOffset; } tmpBout.write(extraCodes._extraCodes); + ++charOffset; } } @@ -988,7 +989,7 @@ public class Index implements Comparable { } // write end extra text - tmpBout.write(END_EXTRA_TEXT); + bout.write(END_EXTRA_TEXT); } /** @@ -1295,7 +1296,8 @@ public class Index implements Comparable { // read the rowId int page = ByteUtil.get3ByteInt(buffer, ByteOrder.BIG_ENDIAN); - int row = buffer.get(); + int row = ByteUtil.toUnsignedInt(buffer.get()); + _rowId = new RowId(page, row); _type = EntryType.NORMAL; } diff --git a/src/java/com/healthmarketscience/jackcess/PageChannel.java b/src/java/com/healthmarketscience/jackcess/PageChannel.java index cd4bd43..5a94c39 100644 --- a/src/java/com/healthmarketscience/jackcess/PageChannel.java +++ b/src/java/com/healthmarketscience/jackcess/PageChannel.java @@ -52,6 +52,8 @@ public class PageChannel implements Channel, Flushable { /** Global usage map always lives on page 1 */ private static final int PAGE_GLOBAL_USAGE_MAP = 1; + /** Global usage map always lives at row 0 */ + private static final int ROW_GLOBAL_USAGE_MAP = 0; /** Channel containing the database */ private final FileChannel _channel; @@ -82,8 +84,8 @@ public class PageChannel implements Channel, Flushable { { // note the global usage map is a special map where any page outside of // the current range is assumed to be "on" - _globalUsageMap = UsageMap.read(database, PAGE_GLOBAL_USAGE_MAP, (byte) 0, - true); + _globalUsageMap = UsageMap.read(database, PAGE_GLOBAL_USAGE_MAP, + ROW_GLOBAL_USAGE_MAP, true); } /** diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 8ec92d4..b87698e 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -580,7 +580,7 @@ public class Table // Overflow page. the "row" data in the current page points to // another page/row - int overflowRowNum = rowBuffer.get(rowStart); + int overflowRowNum = ByteUtil.toUnsignedInt(rowBuffer.get(rowStart)); int overflowPageNum = ByteUtil.get3ByteInt(rowBuffer, rowStart + 1); rowBuffer = rowState.setOverflowRow( new RowId(overflowPageNum, overflowRowNum)); @@ -915,10 +915,12 @@ public class Table _indexSlotCount = tableBuffer.getInt(getFormat().OFFSET_NUM_INDEX_SLOTS); _indexCount = tableBuffer.getInt(getFormat().OFFSET_NUM_INDEXES); - byte rowNum = tableBuffer.get(getFormat().OFFSET_OWNED_PAGES); + int rowNum = ByteUtil.toUnsignedInt( + tableBuffer.get(getFormat().OFFSET_OWNED_PAGES)); int pageNum = ByteUtil.get3ByteInt(tableBuffer, getFormat().OFFSET_OWNED_PAGES + 1); _ownedPages = UsageMap.read(getDatabase(), pageNum, rowNum, false); - rowNum = tableBuffer.get(getFormat().OFFSET_FREE_SPACE_PAGES); + rowNum = ByteUtil.toUnsignedInt( + tableBuffer.get(getFormat().OFFSET_FREE_SPACE_PAGES)); pageNum = ByteUtil.get3ByteInt(tableBuffer, getFormat().OFFSET_FREE_SPACE_PAGES + 1); _freeSpacePages = UsageMap.read(getDatabase(), pageNum, rowNum, false); diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java index bdc0fd4..a6b81ad 100644 --- a/src/java/com/healthmarketscience/jackcess/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java @@ -115,7 +115,7 @@ public class UsageMap * which type of map is found */ public static UsageMap read(Database database, int pageNum, - byte rowNum, boolean assumeOutOfRangeBitsOn) + int rowNum, boolean assumeOutOfRangeBitsOn) throws IOException { JetFormat format = database.getFormat(); -- 2.39.5