google / cpu_features

A cross platform C99 library to get cpu features at runtime.
Apache License 2.0
2.44k stars 258 forks source link

fixed bug for windows-arm64 (introduced in pull request #291) #353

Open NicSavichev opened 3 months ago

NicSavichev commented 3 months ago

https://github.com/google/cpu_features/pull/291 introduced shorter INTROSPECTION_TABLE in impl_aarch64_windows.c so while public headers declare AARCH64LAST=78 only 54 entries were inited in kGetters kFeatureNames. Thus iterating all features upto AARCH64LAST caused crash as long as garbage pointer at kGetters[54] was called. Current implementation seems very unsafe and in order to prevent crash we should check for kGetters array size (that corresponds to INTROSPECTION_TABLE entries). Another solution is static assert for AARCH64LAST == sizeof(kGetters).

google-cla[bot] commented 3 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

toor1245 commented 2 months ago

@NicSavichev, When this patch was added, there was no common INTROSPECTION_TABLE yet and table was sync with linux implementation, could you try to use src/impl_aarch64__base_implementation.inl? For example, https://github.com/google/cpu_features/blob/main/src/impl_aarch64_macos_or_iphone.c#L20