diff --git a/hphp/runtime/ext/gd/ext_gd.cpp b/hphp/runtime/ext/gd/ext_gd.cpp index 080188ca43d18..51f56bec6d247 100644 --- a/hphp/runtime/ext/gd/ext_gd.cpp +++ b/hphp/runtime/ext/gd/ext_gd.cpp @@ -4582,6 +4582,11 @@ Variant HHVM_FUNCTION(iptcembed, const String& iptcdata, return false; } + if (iptcdata_len >= (INT64_MAX - sizeof(psheader) - st_size - 1024 - 1)) { + raise_warning("iptcdata too long"); + return false; + } + auto malloc_size = iptcdata_len + sizeof(psheader) + st_size + 1024 + 1; poi = spoolbuf = (unsigned char *)IM_MALLOC(malloc_size); CHECK_ALLOC_R(poi, malloc_size, false);