8272594: Better record of recordings

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2022-02-01 14:11:06 +00:00 committed by robm
parent 41fe8d2200
commit eb2f497cf0
4 changed files with 15 additions and 2 deletions

View File

@ -66,6 +66,7 @@ final class MetadataReader {
public MetadataReader(RecordingInput input) throws IOException {
this.input = input;
int size = input.readInt();
input.require(size, "Metadata string pool size %d exceeds available data" );
this.pool = new ArrayList<>(size);
StringParser p = new StringParser(null, false);
for (int i = 0; i < size; i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -296,6 +296,7 @@ final class ParserFactory {
@Override
public Object parse(RecordingInput input) throws IOException {
final int size = input.readInt();
input.require(size, "Array size %d exceeds available data" );
final Object[] array = new Object[size];
for (int i = 0; i < size; i++) {
array[i] = elementParser.parse(input);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -418,6 +418,15 @@ public final class RecordingInput implements DataInput, AutoCloseable {
return filename;
}
// Purpose of this method is to prevent OOM by sanity check
// the minimum required number of bytes against what is available in
// segment/chunk/file
public void require(int minimumBytes, String errorMessage) throws IOException {
if (position + minimumBytes > size) {
throw new IOException(String.format(errorMessage, minimumBytes));
}
}
// Purpose of this method is to reuse block cache from a
// previous RecordingInput
public void setFile(Path path) throws IOException {

View File

@ -70,6 +70,7 @@ public final class StringParser extends Parser {
@Override
public Object parse(RecordingInput input) throws IOException {
int size = input.readInt();
input.require(size, "String size %d exceeds available data");
ensureSize(size);
if (lastSize == size) {
boolean equalsLastString = true;
@ -115,6 +116,7 @@ public final class StringParser extends Parser {
@Override
public Object parse(RecordingInput input) throws IOException {
int size = input.readInt();
input.require(size, "String size %d exceeds available data");
ensureSize(size);
if (lastSize == size) {
boolean equalsLastString = true;