roryqi commented on code in PR #15004:
URL: https://github.com/apache/gravitino/pull/15004#discussion_r4610674230


##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/RegisterTableSourceResolver.java:
##########
@@ -98,47 +143,28 @@ private static void collectMatchingTables(
   private static boolean matchesSource(
       IcebergCatalogWrapper catalogWrapper,
       TableIdentifier identifier,
-      String uuid,
       String tableLocation,
-      String metadataLocation) {
+      @Nullable String metadataLocation) {
     Optional<String> currentMeta = 
catalogWrapper.getTableMetadataLocation(identifier);
-    if (currentMeta.isPresent() && 
normalizePath(currentMeta.get()).equals(metadataLocation)) {
-      return true;
+    if (currentMeta.isPresent()) {
+      return matchesPointer(currentMeta.get(), tableLocation, 
metadataLocation);
     }
     try {
       TableMetadata existing = catalogWrapper.loadTableMetadata(identifier);
-      if (uuid != null && uuid.equals(existing.uuid())) {
-        return true;
-      }
-      return tableLocation != null
-          && !tableLocation.isEmpty()
-          && tableLocation.equals(normalizePath(existing.location()));
+      return IcebergTableLocationUtils.overlaps(tableLocation, 
existing.location());
     } catch (NoSuchTableException e) {
-      // Only a table that no longer exists is unrelated. Any other failure to 
read its metadata
-      // must not be mistaken for unrelated metadata, which would skip source 
authorization.
       return false;
     }
   }
 
-  /** Normalizes path strings so {@code file:/} and {@code file:///} compare 
equal. */
-  public static String normalizePath(String path) {
-    if (path == null) {
-      return "";
-    }
-    String trimmed = path.trim();
-    if (trimmed.startsWith("file:")) {
-      String withoutScheme = trimmed.substring("file:".length());
-      while (withoutScheme.startsWith("//")) {
-        withoutScheme = withoutScheme.substring(1);
-      }
-      if (!withoutScheme.startsWith("/")) {
-        withoutScheme = "/" + withoutScheme;
-      }
-      return "file:" + withoutScheme;
-    }
-    if (trimmed.endsWith("/")) {
-      return trimmed.substring(0, trimmed.length() - 1);
+  private static boolean matchesPointer(
+      String pointer, String location, @Nullable String metadataLocation) {
+    if (metadataLocation != null
+        && normalizePath(pointer).equals(normalizePath(metadataLocation))) {
+      return true;
     }
-    return trimmed;
+    return IcebergTableLocationUtils.tableLocation(pointer)

Review Comment:
   This is the same older-snapshot case discussed in [the original 
thread](https://github.com/apache/gravitino/pull/15004#discussion_r4599597944). 
We agree on the reproduction and that this loses an existing authorization 
protection. The exact-current-pointer fix was explicitly partial; the merge 
from main did not attempt to address this remaining case.
   
   The scope I am proposing for this PR is standard `<table>/metadata/<file>` 
layouts, using one JDBC query without catalog-wide metadata-file reads, a new 
cache, or a new persisted location index. Exact current-pointer matching is 
retained as an additional protection, not as complete support for custom 
layouts.
   
   For arbitrary historical metadata in a custom layout, pointer matching alone 
does not establish the authoritative table location. Restoring the old metadata 
scan would reintroduce the I/O this optimization removes; maintaining 
authoritative location information needs a broader persistence/lifecycle 
design. Fail-closed handling is also an option, but it introduces a rejection 
policy for registrations that were previously accepted. I am not claiming that 
fixing this is technically impossible or that the authorization regression is 
harmless.
   
   I am proposing to defer that broader custom-layout behavior, and I am **not 
asking to mark this finding fixed**. The remaining disagreement is whether this 
restricted scope is acceptable for merging. Please keep this as a carried-over 
finding in the original thread so we can focus on that scope/merge decision 
rather than opening duplicate findings for unchanged behavior.



-- 
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]

Reply via email to