nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
25.77k stars 7.66k forks source link

Malloc return not checked in stbi_write_hdr_core #1645

Open catenacyber opened 1 month ago

catenacyber commented 1 month ago

Describe the bug https://github.com/nothings/stb/blob/master/stb_image_write.h#L767 does not check the malloc return value, when it can be NULL and later dereferenced

To Reproduce Found with CodeQL query https://github.com/github/codeql/pull/16524 (only finding in this project)

Expected behavior Check the return value, and return early as in the other cases like https://github.com/nothings/stb/blob/master/stb_image_write.h#L909

Simple patch like would be to ass

if (scratch == NULL)
  return 0;