Skip to content

fix: prevent file corruption in transform download#219

Open
bhsf-james-pannell wants to merge 1 commit intosailpoint-oss:mainfrom
bhsf-james-pannell:fix/transform-download-filename-collision
Open

fix: prevent file corruption in transform download#219
bhsf-james-pannell wants to merge 1 commit intosailpoint-oss:mainfrom
bhsf-james-pannell:fix/transform-download-filename-collision

Conversation

@bhsf-james-pannell
Copy link

he sail transform download command produces corrupted JSON files in two scenarios:

1. Re-downloading to existing folder

WriteFile uses O_CREATE|O_RDWR without O_TRUNC. When new content is shorter than existing file content, leftover bytes remain, producing invalid JSON.

2. Filename collisions

Transform names like "AD - samAccountName" and "AD-samAccountName" both sanitize to AD-samAccountName.json. The second overwrites the first, and combined with bug #1, produces merged/corrupted content.

Changes

  • Add O_TRUNC flag to WriteFile to properly truncate existing files
  • Add filename collision detection using in-memory map (appends -1, -2, etc.)
  • Use sanitize.PathName directly instead of manual space stripping
  • Change O_RDWR to O_WRONLY (write-only, since we never read)

Bug: Missing O_TRUNC

Original file (first download):

{
  "name": "ToUpper",
  "type": "upper",
  "attributes": {
    "input": { "type": "identityAttribute" }
  }
}

After transform is updated and re-downloaded (shorter content):

{
  "name": "ToUpper",
  "type": "upper"
}put": { "type": "identityAttribute" }
  }
}

Bug: Filename Collision

First transform written:

{
  "name": "AD - samAccountName",
  "type": "accountAttribute",
  "attributes": {
    "sourceName": "Active Directory"
  }
}

Second transform overwrites (shorter, same sanitized filename):

{
  "name": "AD-samAccountName",
  "type": "static"
}ountAttribute",
  "attributes": {
    "sourceName": "Active Directory"
  }
}

After Fix

transforms/
├── AD-samAccountName.json    # first transform preserved
├── AD-samAccountName-1.json  # collision handled
└── ToUpper.json              # clean on re-download (O_TRUNC)

- Add O_TRUNC flag to WriteFile to properly truncate existing files
- Add filename collision detection using in-memory map
- Use sanitize.PathName directly instead of manual space stripping

Fixes issue where re-downloading transforms or downloading transforms
with similar names that sanitize identically would produce corrupted
or overwritten JSON files.
Copilot AI review requested due to automatic review settings January 29, 2026 02:27
@CLAassistant
Copy link

CLAassistant commented Jan 29, 2026

CLA assistant check
All committers have signed the CLA.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes corrupted JSON output produced by sail transform download by ensuring files are correctly overwritten and by reducing accidental overwrites from filename collisions.

Changes:

  • Truncate existing files on write to prevent leftover trailing bytes from prior content.
  • Generate unique filenames for transforms whose names sanitize to the same base filename.
  • Use sanitize.PathName for consistent filename sanitization and switch file open mode to write-only.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/output/output.go Updates file open flags to include truncation (O_TRUNC) when overwriting files.
cmd/transform/download.go Adds sanitized filename generation plus in-memory collision handling for transform downloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codey-bot
Copy link

codey-bot bot commented Jan 29, 2026

🎉 Thanks for opening this pull request! Please be sure to check out our contributing guidelines. 🙌

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.

3 participants