diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/DBStatus.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/DBStatus.java index 94fd4bf1d76..b4e5e9f9032 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/DBStatus.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/DBStatus.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems and others. + * Copyright (c) 2005, 2012 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,4 +26,8 @@ public class DBStatus extends Status { public DBStatus(IOException exception) { super(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, "IOException", exception); //$NON-NLS-1$ } + + public DBStatus(String msg) { + super(IStatus.ERROR, CCorePlugin.PLUGIN_ID, 0, "Error", null); //$NON-NLS-1$ + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java index 33248fba103..6e5bdc27242 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java @@ -29,6 +29,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; +import com.ibm.icu.text.MessageFormat; + /** * Database encapsulates access to a flat binary format file with a memory-manager-like API for * obtaining and releasing areas of storage (memory). @@ -263,7 +265,10 @@ public class Database { synchronized (fCache) { assert fLocked; - final int index = (int)long_index; + final int index = (int) long_index; + if (index < 0 || index >= fChunks.length) { + databaseCorruptionDetected(); + } Chunk chunk= fChunks[index]; if (chunk == null) { cacheMisses++; @@ -277,6 +282,12 @@ public class Database { } } + private void databaseCorruptionDetected() throws CoreException { + String msg = MessageFormat.format(Messages.getString("Database.CorruptedDatabase"), //$NON-NLS-1$ + new Object[] { fLocation.getName() }); + throw new CoreException(new DBStatus(msg)); + } + /** * Allocate a block out of the database. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties index b342cac1136..e3e7e208ab8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/messages.properties @@ -16,3 +16,4 @@ BTree.IntegrityErrorA=[{0} blanks inconsistent b={1} nb={2}] BTree.IntegrityErrorB=[{0} wrong number of children with respect to key count] BTree.IntegrityErrorC=[{0} key count out of range] BTree.IntegrityErrorD=Leaf nodes at differing depths +Database.CorruptedDatabase=Corrupted database: {0}