### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/index/DiskIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java,v retrieving revision 1.72 diff -u -r1.72 DiskIndex.java --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 26 Oct 2010 17:24:15 -0000 1.72 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 18 Aug 2011 12:42:15 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation 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 @@ -783,7 +783,13 @@ this.sizeOfLastChunk = this.streamBuffer[this.bufferIndex++] & 0xFF; this.documentReferenceSize = this.streamBuffer[this.bufferIndex++] & 0xFF; this.separator = (char) (this.streamBuffer[this.bufferIndex++] & 0xFF); - + long fileLength = this.indexFile.length(); + if (this.numberOfChunks > fileLength ) { + // not an accurate check, but good enough https://bugs.eclipse.org/bugs/show_bug.cgi?id=350612 + if (DEBUG) + System.out.println("Index file is corrupted " + this.indexFile); //$NON-NLS-1$ + throw new IOException("Index file is corrupted " + this.indexFile); //$NON-NLS-1$ + } this.chunkOffsets = new int[this.numberOfChunks]; for (int i = 0; i < this.numberOfChunks; i++) this.chunkOffsets[i] = readStreamInt(stream); @@ -793,6 +799,12 @@ int size = readStreamInt(stream); this.categoryOffsets = new HashtableOfIntValues(size); this.categoryEnds = new HashtableOfIntValues(size); + if (size > fileLength) { + // not an accurate check, but good enough https://bugs.eclipse.org/bugs/show_bug.cgi?id=350612 + if (DEBUG) + System.out.println("Index file is corrupted " + this.indexFile); //$NON-NLS-1$ + throw new IOException("Index file is corrupted " + this.indexFile); //$NON-NLS-1$ + } char[] previousCategory = null; int offset = -1; for (int i = 0; i < size; i++) {