wombatu-kun commented on code in PR #16500:
URL: https://github.com/apache/iceberg/pull/16500#discussion_r3315057274
##########
core/src/main/java/org/apache/iceberg/util/ContentFileUtil.java:
##########
@@ -156,6 +156,27 @@ public static String dvDesc(DeleteFile deleteFile) {
deleteFile.referencedDataFile());
}
+ /**
+ * Validates that the deletion-vector offset and length on a {@link
DeleteFile} are well-formed
+ * before they are consumed by a reader. Hostile or corrupted manifest
metadata may otherwise
+ * trigger a {@link NegativeArraySizeException}, an invalid seek, or a
multi-gigabyte allocation
+ * when the DV blob is read.
+ */
+ public static void validateDV(DeleteFile dv) {
+ Preconditions.checkArgument(
+ dv.contentOffset() != null, "Invalid DV, offset cannot be null: %s",
dvDesc(dv));
+ Preconditions.checkArgument(
+ dv.contentSizeInBytes() != null, "Invalid DV, length cannot be null:
%s", dvDesc(dv));
+ Preconditions.checkArgument(
+ dv.contentOffset() >= 0, "Invalid DV, offset must be non-negative:
%s", dvDesc(dv));
+ Preconditions.checkArgument(
+ dv.contentSizeInBytes() >= 0, "Invalid DV, length must be
non-negative: %s", dvDesc(dv));
+ Preconditions.checkArgument(
+ dv.contentSizeInBytes() <= Integer.MAX_VALUE,
Review Comment:
Fixed in eacedd538.
##########
core/src/main/java/org/apache/iceberg/DVUtil.java:
##########
@@ -52,6 +52,7 @@ static PositionDeleteIndex readDV(DeleteFile deleteFile,
FileIO fileIO) {
ContentFileUtil.isDV(deleteFile),
"Cannot read, not a deletion vector: %s",
deleteFile.location());
+ ContentFileUtil.validateDV(deleteFile);
Review Comment:
Done in eacedd538. DVUtil is now public so BaseDeleteLoader (data module)
can call it.
##########
core/src/main/java/org/apache/iceberg/FileMetadata.java:
##########
@@ -263,6 +263,12 @@ public DeleteFile build() {
if (format == FileFormat.PUFFIN) {
Preconditions.checkArgument(contentOffset != null, "Content offset is
required for DV");
Preconditions.checkArgument(contentSizeInBytes != null, "Content size
is required for DV");
+ Preconditions.checkArgument(
+ contentOffset >= 0, "Content offset must be non-negative for DV:
%s", contentOffset);
+ Preconditions.checkArgument(
+ contentSizeInBytes >= 0,
Review Comment:
Done in eacedd538.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]