Skip to content

Commit

Permalink
This fixes issue epam#58. Remove "todo" to pass checkstyle check.
Browse files Browse the repository at this point in the history
  • Loading branch information
tballison committed Apr 24, 2020
1 parent f07c870 commit 931ce61
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/epam/parso/impl/SasFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public final class SasFileParser {
*/
private static final Map<String, Decompressor> LITERALS_TO_DECOMPRESSOR = new HashMap<String, Decompressor>();

//sanity check on maximum page length
private static final int MAX_PAGE_LENGTH = 10000000;

static {
Map<Long, SubheaderIndexes> tmpMap = new HashMap<Long, SubheaderIndexes>();
tmpMap.put((long) 0xF7F7F7F7, SubheaderIndexes.ROW_SIZE_SUBHEADER_INDEX);
Expand Down Expand Up @@ -326,7 +329,12 @@ private void processSasFileHeader(String builderEncoding) throws IOException {
sasFileProperties.setDateCreated(bytesToDateTime(vars.get(4)));
sasFileProperties.setDateModified(bytesToDateTime(vars.get(5)));
sasFileProperties.setHeaderLength(bytesToInt(vars.get(6)));
sasFileProperties.setPageLength(bytesToInt(vars.get(7)));
int pageLength = bytesToInt(vars.get(7));
if (pageLength > MAX_PAGE_LENGTH) {
throw new IOException("Page limit ("
+ pageLength + ") exceeds maximum: "+MAX_PAGE_LENGTH);
}
sasFileProperties.setPageLength(pageLength);
sasFileProperties.setPageCount(bytesToLong(vars.get(8)));
sasFileProperties.setSasRelease(bytesToString(vars.get(9)).trim());
sasFileProperties.setServerType(bytesToString(vars.get(10)).trim());
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/epam/parso/BugsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ public void testInfiniteLoop() throws Exception {
assertEquals(0, rowCount);
}
}

@Test
public void testOOM() throws Exception {
try (InputStream is =
Files.newInputStream( Paths.get(this.getClass().getResource(
"/bugs/mixed_data_one.sas7bdat.om").toURI()))) {
SasFileReader sasFileReader = new SasFileReaderImpl(is);

long rowCount = sasFileReader.getSasFileProperties().getRowCount();
assertEquals(0, rowCount);
}
}
}
Binary file not shown.

0 comments on commit 931ce61

Please sign in to comment.