title: lodsb instruction causes a stack overflow
body: <p>I want to search for a pattern in memory of current process. I query for memory pages using VirtualQuery to extract ranges of interest. The problem is that after 5 minutes of continous looping the program crashes by a stackoverflow. The size of allocated memory by the process gets bigger.</p>
  
  <p>The problem resides in this loop:</p>
  
  <pre><code>valid_range:
      pushad
      mov eax, [ebp]
      mov esi, [eax] ; memory range start
      mov ecx, [eax + 12] ; memory range size
      xor eax, eax
  
  loopmem:
      lodsb ; this causes stackoverflow after certain time ????
      dec ecx
      cmp ecx, 0 ; we loop trough memory until we finish it
  ; reduced the code to minimum
          je finish_range
          jmp loopmem
  
  
  finish_range:
      popad
      ret 
  </code></pre>