Skip to content

SafeInteropWrapper crashes with 'cgImage.width' #80948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 30, 2025
Merged

Conversation

rapidsna
Copy link
Contributor

@rapidsna rapidsna commented Apr 21, 2025

cgImage.width calls the C function, CGImageGetWidth(CGImageRef).
Swift representation and Clang representation of this function
seem to have a parameter number mismatch, causing swiftify function
to crash.

rdar://149691207

@rapidsna
Copy link
Contributor Author

@swift-ci test

@rapidsna rapidsna changed the title [Swiftify] Fix crash in the use getter [Swiftify] SafeInteropWrapper crashes with 'cgImage.width' Apr 21, 2025
@rapidsna
Copy link
Contributor Author

@swift-ci smoke test

@@ -9159,6 +9159,8 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
returnHasLifetimeInfo = true;
}
for (auto [index, clangParam] : llvm::enumerate(ClangDecl->parameters())) {
if (index >= MappedDecl->getParameters()->size())
Copy link
Contributor

Choose a reason for hiding this comment

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

While this protects against the crash, I don't think we want to apply _SwiftifyImport in any case where there's a parameter mismatch, since they could all be off by 1. I would suggest changing it to an early exit before the loop:

if (ClangDecl->parameters()->size() != MappedDecl->getParameters()->size())
  return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

cgImage.width calls the C function, CGImageGetWidth(CGImageRef).
Swift representation and Clang representation of this function
seem to have a parameter number mismatch, causing swiftify function
to crash.

rdar://149691207
@rapidsna
Copy link
Contributor Author

@swift-ci smoke test

@hnrklssn hnrklssn self-requested a review April 24, 2025 16:23
@rapidsna
Copy link
Contributor Author

@swift-ci smoke test

@rapidsna rapidsna enabled auto-merge (squash) April 29, 2025 00:26
@rapidsna
Copy link
Contributor Author

@swift-ci smoke test

@rapidsna
Copy link
Contributor Author

@swift-ci smoke test

@rapidsna
Copy link
Contributor Author

@swift-ci smoke test

@rapidsna rapidsna merged commit 2d7b7a7 into main Apr 30, 2025
3 checks passed
@rapidsna rapidsna deleted the eng/PR-149691207 branch April 30, 2025 15:53
@rapidsna rapidsna changed the title [Swiftify] SafeInteropWrapper crashes with 'cgImage.width' SafeInteropWrapper crashes with 'cgImage.width' May 8, 2025
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