摘要:In an internal email, someone wrote malloc(width * height * sizeof(int)) to allocate an integer matrix of width x height. If you think carefully about this simple line of code, it's potentially dangerous. Suppose you're providing a webpage which allows user to enter a matrix and then perform some compliated calculation. The matrix is entered as: width height a00 a01 a02 ... a10 a11 a12 .... If someone enters width = 32769 and height 32768, malloc(width * height * sizeof(int)) will allocate 32769 x 32768 * 4 bytes of memory. This value is is 32768 * 4 = 128 kb in 32-bit......[阅读全文]