uros-b opened a new pull request, #17521:
URL: https://github.com/apache/iceberg/pull/17521

   `RewriteTablePathUtil.replacePaths` rewrote the table location with
   `String.replaceFirst(sourcePrefix, targetPrefix)`, which interprets the 
user-supplied
   `sourcePrefix` as a **regular expression** and `targetPrefix` as a 
**replacement string**.
   Both are file paths, so this misbehaves whenever a path contains regex 
metacharacters:
   
   - `sourcePrefix = s3://bucket/warehouse.db/table` also matches
     `s3://bucket/warehouseXdb/table`, rewriting a location that is not under 
the prefix.
   - A `sourcePrefix` with a trailing separator (e.g. 
`s3://bucket/warehouse/table/`) does not
     match at all, so the location is silently left pointing at the **source** 
while every
     other path is rewritten to the target.
   - A `targetPrefix` containing `$` fails with `IndexOutOfBoundsException: No 
group 1`, and a
     path containing an unbalanced `[` fails with `PatternSyntaxException`.
   
   Every other path rewrite in this class already goes through `newPath()` -> 
`relativize()`,
   which compares prefixes literally (`startsWith` + `substring`), normalizes 
trailing
   separators, and raises a clear `IllegalArgumentException` when a path is not 
under the
   source prefix. In `RewriteTablePathSparkAction#rewriteVersionFile` the 
immediately
   preceding `stagingPath(...)` call already applies that literal check, so 
this change makes
   the location rewrite consistent with the validation already performed one 
line earlier.
   
   Both prefixes are user-supplied through the public
   `RewriteTablePath.rewriteLocationPrefix(sourcePrefix, targetPrefix)` API.
   
   Tested with `TestRewriteTablePathUtil` (core) and 
`TestRewriteTablePathsAction` on Spark
   3.5, 4.0 and 4.1.
   
   Note: #14355 makes the same one-line change as a side effect of adding 
multiple
   source/destination prefixes. This is the minimal standalone fix plus 
regression tests for
   the metacharacter and trailing-separator cases, so it can land 
independently; whichever
   merges first, the other should rebase cleanly on this method.
   
   ---
   **AI Disclosure**
   - Model: Claude Opus 4.8
   - Platform/Tool: Claude Code
   - Human Oversight: fully reviewed
   - Prompt Summary: Fix a call site that treated a user-supplied path prefix 
as a regex, and add regression tests.
   


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

Reply via email to