Skip to content

[ISSUE #11500] Prevent copying a file onto itself - #11501

Open
Drifter-yh wants to merge 1 commit into
apache:developfrom
Drifter-yh:fix-iotinyutils-same-file
Open

Drifter-yh wants to merge 1 commit into
apache:developfrom
Drifter-yh:fix-iotinyutils-same-file

Conversation

@Drifter-yh

@Drifter-yh Drifter-yh commented Oct 29, 2026 •

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #11500

Brief Description

Opening the target truncates it before the source is opened. If the two paths refer to the same existing file, including a hard link, this silently destroys the source. Reject that case with an IOException before opening the destination. Normal copies retain their existing behavior.

This public utility has no production call sites in this repository; no broker-level data-loss scenario is claimed. This does not address the separate relative-target issue #11461.

How Did You Test This Change?

  • On 592d59d12db356f8c98332d9e355a89d92590db3, the same-path regression failed before the fix: expected 14 bytes, got zero.
  • mvn -B -ntp -pl common -am -Dtest=IOTinyUtilsTest,IOTinyUtilsSameFileTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test on Windows 11, Microsoft OpenJDK 17.0.14 and Maven 3.9.2: 11 tests passed, 0 failures/errors/skips; Checkstyle and SpotBugs passed. The three new cases cover the same path, a hard link, and a distinct target. The hard-link case skips if the filesystem cannot create one.
  • git diff --check passed. No broker integration test or full-project test is claimed.

AI assistance: OpenAI Codex was used for analysis, implementation, and tests; the changes were reviewed and tested as described above.

CI: GitHub Actions runs for head 7105dffc report action_required; no jobs or passing checks are reported yet. The reason is not confirmed.

@Drifter-yh
Drifter-yh force-pushed the fix-iotinyutils-same-file branch from ae14558 to 7105dff Compare October 29, 2026 15:50
@Drifter-yh
Drifter-yh marked this pull request as ready for review October 29, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] IOTinyUtils.copyFile truncates the source when paths refer to the same file

1 participant