[ https://issues.apache.org/jira/browse/PARQUET-2094?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17420550#comment-17420550 ]
ASF GitHub Bot commented on PARQUET-2094: ----------------------------------------- gszadovszky commented on a change in pull request #933: URL: https://github.com/apache/parquet-mr/pull/933#discussion_r716452332 ########## File path: parquet-format-structures/src/main/java/org/apache/parquet/format/MetadataValidator.java ########## @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.parquet.format; + +import java.io.IOException; +import java.util.function.Predicate; + +/** + * Utility class to validate different types of Parquet metadata (e.g. footer, page headers etc.). + */ +public class MetadataValidator { + + /** + * A specific IOException thrown when invalid values are found in the Parquet file metadata (including the footer, + * page header etc.). + */ + public static class InvalidParquetMetadataException extends IOException { + private <T> InvalidParquetMetadataException(String metaName, T value) { + super("Metadata " + metaName + " is invalid: " + value); + } + } + + static PageHeader validate(PageHeader pageHeader) throws InvalidParquetMetadataException { + validateValue(size -> size >= 0, pageHeader.getCompressed_page_size(), "pageHeader.compressed_page_size"); + return pageHeader; + } + + private static <T> void validateValue(Predicate<? super T> validator, T value, String metaName) Review comment: I am not sure why I've implemented this way. I'm fine rewriting to use a simple boolean. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@parquet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Handle negative values in page headers > -------------------------------------- > > Key: PARQUET-2094 > URL: https://issues.apache.org/jira/browse/PARQUET-2094 > Project: Parquet > Issue Type: Bug > Reporter: Gabor Szadovszky > Assignee: Gabor Szadovszky > Priority: Major > > There are integer values in the page headers that should be always positive > (e.g. length). I am not sure if we properly handle the cases if they are not > positive. -- This message was sent by Atlassian Jira (v8.3.4#803005)