Skip to content

Commit

Permalink
Merge pull request #1127 from Bykiev/FixBug874
Browse files Browse the repository at this point in the history
Fix reading xls
  • Loading branch information
tonyqus authored Jul 29, 2023
2 parents 4046e09 + d2be582 commit cc5238b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions main/POIFS/FileSystem/NPOIFSFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions main/Util/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,18 @@ public static int ReadFully(Stream stream, byte[] b)

/// <summary>
/// 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
/// </summary>
/// <param name="stream">the stream from which the data is read.</param>
/// <param name="b">the buffer into which the data is read.</param>
/// <param name="off">the start offset in array b at which the data is written.</param>
/// <param name="len">the maximum number of bytes to read.</param>
/// <returns></returns>
/// <returns>the number of bytes read or -1 if no bytes were read</returns>
public static int ReadFully(Stream stream, byte[] b, int off, int len)
{
int total = 0;
Expand Down
7 changes: 7 additions & 0 deletions testcases/main/HSSF/UserModel/TestHSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,5 +1473,12 @@ public void TestWriteToNewFile()
Assert.AreEqual(3, wb.NumberOfSheets);
wb.Close();
}


[Test]
public void TestBug854()
{
Assert.DoesNotThrow(() => HSSFTestDataSamples.OpenSampleWorkbook("ATM.xls"));
}
}
}
Binary file added testcases/test-data/spreadsheet/ATM.xls
Binary file not shown.

0 comments on commit cc5238b

Please sign in to comment.