1

I expected that Pageheap will force my application to crash while executing the 2nd and 3rd statements in the below code piece. But this is not happening. I enabled full page heap for the application.

What extra things should I do to make pageheap to break my application at second and third statements?

char *test =new char[12];
memset(test,'c',15);
test[13] = 'c';

But If I use, the following statement pagebreak will break my application

memset(test,'c',50);
sth
  • 222,467
  • 53
  • 283
  • 367
Maanu
  • 5,093
  • 11
  • 59
  • 82

1 Answers1

2

Allocations are rounded up N bytes, where N is a multiple of 8 and depends on which version of Windows you're using. Let's assume allocations are rounded up to the nearest 8 bytes, for this case.

Pageheap works by inserting a 'guard page' at the end of each allocation and protecting it from read/write access, so any attempt to use it will result in an access violation.

In this case, your allocation of test is requesting 12 bytes. The heap manager is actually giving you an allocation of 16 bytes. Accessing test[15] is within this allocation, so it's not hitting the guard page.

On one additional note, I believe a full pageheap will fill the 'extra' memory returned by an allocation with some special value. When you free the allocation, it will check the 'extra' memory and raise an exception if the value was changed.

Collin Dauphinee
  • 13,664
  • 1
  • 40
  • 71
  • Thanks. When I added the code in another application named ICECon, PageHeap does not make the application break at memset(test,'c',50);, Instead it breaks after executing some other methods after the memset statement. What could be the reason? – Maanu May 08 '11 at 11:38
  • @Maanu: you can dump your 'test' buffer in the debugger. Then you will see where the guard page starts (unreadable memory). – glagolig Sep 07 '13 at 23:41