diff --git a/main/POIFS/FileSystem/NPOIFSFileSystem.cs b/main/POIFS/FileSystem/NPOIFSFileSystem.cs index bd9e7e3ce..00bbaf725 100644 --- a/main/POIFS/FileSystem/NPOIFSFileSystem.cs +++ b/main/POIFS/FileSystem/NPOIFSFileSystem.cs @@ -310,8 +310,8 @@ public NPOIFSFileSystem(Stream stream) data.Write(headerBuffer.Buffer); data.Position = headerBuffer.Length; - //IOUtils.ReadFully(channel, data); - data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)channel.Length); + //IOUtils.ReadFully(channel, data.Buffer); + data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)maxSize); success = true; // Turn it into a DataSource diff --git a/main/Util/IOUtils.cs b/main/Util/IOUtils.cs index 1b4b00a5d..6c00ecc11 100644 --- a/main/Util/IOUtils.cs +++ b/main/Util/IOUtils.cs @@ -178,19 +178,18 @@ public static int ReadFully(Stream stream, byte[] b) /// /// Same as the normal InputStream#read(byte[], int, int), but tries to ensure - /// that the buffer is filled completely if possible, i.e. b.remaining() - /// returns 0. - /// If the end of file is reached before any bytes are Read, returns -1. + /// that the entire len number of bytes is read + /// + /// If the end of file is reached before any bytes are read, returns -1. /// If the end of the file is reached after some bytes are read, returns the /// number of bytes read. If the end of the file isn't reached before the - /// buffer has no more remaining capacity, will return the number of bytes - /// that were read. + /// buffer has no more remaining capacity, will return len bytes /// /// the stream from which the data is read. /// the buffer into which the data is read. /// the start offset in array b at which the data is written. /// the maximum number of bytes to read. - /// + /// the number of bytes read or -1 if no bytes were read public static int ReadFully(Stream stream, byte[] b, int off, int len) { int total = 0; diff --git a/testcases/main/HSSF/UserModel/TestHSSFWorkbook.cs b/testcases/main/HSSF/UserModel/TestHSSFWorkbook.cs index c17453eeb..866addf61 100644 --- a/testcases/main/HSSF/UserModel/TestHSSFWorkbook.cs +++ b/testcases/main/HSSF/UserModel/TestHSSFWorkbook.cs @@ -1473,5 +1473,12 @@ public void TestWriteToNewFile() Assert.AreEqual(3, wb.NumberOfSheets); wb.Close(); } + + + [Test] + public void TestBug854() + { + Assert.DoesNotThrow(() => HSSFTestDataSamples.OpenSampleWorkbook("ATM.xls")); + } } } diff --git a/testcases/test-data/spreadsheet/ATM.xls b/testcases/test-data/spreadsheet/ATM.xls new file mode 100644 index 000000000..625b072d6 Binary files /dev/null and b/testcases/test-data/spreadsheet/ATM.xls differ