When two memset struct with the same name will crash on ios18 beta1

1.The code structure is as follows: The main project imports an SDK.

2.The main project defines a struct A with a length of 1400 bytes, and the SDK also defines a struct A with a length of 1000 bytes.

3.The SDK does not expose the definition of struct A, but it is used in the implementation of the exposed API in the SDK.

4.In the usage process, the main project first calls the SDK's API, which uses struct A of SDK's and initializes it with memset. Then, in the main project, memset is used again to initialize the struct A declared in the main project.

  1. In the above scenario, it works fine on iOS versions lower than iOS18, but on iOS18 beat1, the app crashes randomly, and the crash scenarios are not fixed.

We need to know whether iOS18 has made any improvements to the API for operating memory such as memset. Is memory management more stringent? Why do versions below iOS18 not cause problems?

Thanks!

Answered by endecotp in 791927022

We want to try to find a more specific cause of the error.

That’s probably not a productive use of your time.

Instead, spend the time learning how to use Address Sanitizer, and see if it can find any other similar bugs in your app.

If I understand you correctly, you are re-declaring struct A, exposed via a pointer in the SDK, from a 1000 byte struct to a 1400 byte struct. If it is allocated in the SDK (1000 bytes), and you memset it from main (1400 bytes), memset will run off the end of the struct and overwrite 400 bytes of memory, somewhere, with unpredictable effects.

Did you expect this to reliably crash at any time, on any OS? Did you expect it to be benign? memset will do what it is asked to do.

We need to know whether iOS18 has made any improvements to the API for operating memory such as memset.

No.

Is memory management more stringent?

No.

Why do versions below iOS18 not cause problems?

You were lucky.

The important question is: why did you not get a compiler error, or at least a warning, about this? Were you ignoring warnings?

We want to try to find a more specific cause of the error.

That’s probably not a productive use of your time.

Instead, spend the time learning how to use Address Sanitizer, and see if it can find any other similar bugs in your app.

Instead, spend the time learning how to use Address Sanitizer, and see if it can find any other similar bugs in your app.

Agreed!

Apple regularly updates how memory management is done on our system, and there definitely have been changes in the iOS 18 beta. To work reliably your app must follow the rules, and ASan is a great way to uncover places where you are not.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

When two memset struct with the same name will crash on ios18 beta1
 
 
Q