<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : [SOLVED]CXTPHexEdit crash when replacing Data buff</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Controls : [SOLVED]CXTPHexEdit crash when replacing Data buff]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Tue, 12 May 2026 20:13:33 +0000</pubDate>
  <lastBuildDate>Mon, 06 Sep 2021 04:35:36 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=24202</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[[SOLVED]CXTPHexEdit crash when replacing Data buff : Ok, I changed our code. You right.void...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78226&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78226</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=9012">agontarenko</a><br /><strong>Subject:</strong> 24202<br /><strong>Posted:</strong> 06 September 2021 at 4:35am<br /><br /><div>Ok, I changed our code. You right.<br></div><div><br></div><div>void CXTPHexEdit::SetData(LPBYTE p, int nLength, int nMaxLength)<br>{<br>&nbsp;&nbsp; &nbsp;if (m_pData)<br>&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; free(m_pData);</div><div>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; m_nLength = 0;</div><div>&nbsp;&nbsp;&nbsp; }</div><div><br></div><div><br></div><div>Thanks.<br></div>]]>
   </description>
   <pubDate>Mon, 06 Sep 2021 04:35:36 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78226&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78226</guid>
  </item> 
  <item>
   <title><![CDATA[[SOLVED]CXTPHexEdit crash when replacing Data buff : As you don&amp;#039;t seem to understand:...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78225&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78225</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=9501">grumat</a><br /><strong>Subject:</strong> 24202<br /><strong>Posted:</strong> 06 September 2021 at 3:44am<br /><br /><div>As you don't seem to understand: I <b>have</b> a fix for your bug and I am <b>sharing</b> it to you. There are enough information for a regular experienced programmer understand and <b>fix</b> the issue.</div><div><br></div><div>If you are not interested in the "continuous product improvement", then please close the issue. I won't annoy you anymore.<br></div>]]>
   </description>
   <pubDate>Mon, 06 Sep 2021 03:44:29 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78225&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78225</guid>
  </item> 
  <item>
   <title><![CDATA[[SOLVED]CXTPHexEdit crash when replacing Data buff : Hello,I understood that you have...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78224&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78224</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=9012">agontarenko</a><br /><strong>Subject:</strong> 24202<br /><strong>Posted:</strong> 06 September 2021 at 3:35am<br /><br />Hello,<br><div><br></div><div>I understood that you have problem. For a solution, I need to reproduce this bug.<br>Can you change HexEdit sample that the problem is reproducible, and attach it to topic.<br><br>Also, in v20.0 or 20.1 has been some changes, may be this problem already fixed.<br></div>Regards,<br>Artem Gontarenko&nbsp; <br>]]>
   </description>
   <pubDate>Mon, 06 Sep 2021 03:35:37 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78224&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78224</guid>
  </item> 
  <item>
   <title><![CDATA[[SOLVED]CXTPHexEdit crash when replacing Data buff : Just see your source code:XTPHexEdit.cpp:void...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78223&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78223</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=9501">grumat</a><br /><strong>Subject:</strong> 24202<br /><strong>Posted:</strong> 03 September 2021 at 4:27am<br /><br /><div>Just see your source code:</div><div>XTPHexEdit.cpp:</div><font face="Courier New, Courier, mono">void CXTPHexEdit::SetData(LPBYTE p, int nLength, int nMaxLength)<br>{<br>&nbsp;&nbsp;&nbsp; if (m_pData)<br></font><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color="#FF0000"> <b>free(m_pData);</b><br></font><br>&nbsp;&nbsp;&nbsp; m_pData = (LPBYTE)malloc(nLength);<br>&nbsp;&nbsp;&nbsp; MEMCPY_S(m_pData, p, nLength);<br><br>&nbsp;&nbsp;&nbsp;<font color="#FF0000"> <b>SetSel(-1, -1);</b></font><br>&nbsp;&nbsp;&nbsp; m_nMaxLength&nbsp;&nbsp;&nbsp; &nbsp; = nMaxLength &lt; 0 ? -1 : __max(nMaxLength, nLength);<br>&nbsp;&nbsp;&nbsp; <b><font color="#FF0000">m_nLength&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; = nLength;</font></b><br>...</font></div><div><font face="Courier New, Courier, mono"><br></font></div><div>See the bold lines: You free the old buffer, then allocates the new buffer with the new length. Before updating the new buffer bound (<b><font face="Courier New, Courier, mono">m_nLength</font></b>) you issue a <b>SetSel</b>, which "may" cause a <b><font face="Courier New, Courier, mono">WM_PAINT</font></b>.</div><div><br></div><div><font face="Courier New, Courier, mono">void CXTPHexEdit::SetSel(int nSelStart, int nSelEnd)<br>{</font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; ...<br></font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; <b>RedrawWindow();</b><br></font><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; ...<br></font></div><font face="Courier New, Courier, mono">}<br></font></div><div><br></div><div>The <b>OnDraw </b>checks <b>m_nLength</b> to keep access within the buffer bounds, but since the order of the previous code has a flaw, the <b>m_nLength</b> is <b>not</b> valid for the new buffer. This is critical if the new size of the buffer <b>decreases</b>. The use case requires an initial "big buffer" and also that we "scroll to the end of that buffer". So when a tiny new buffer is newly applied, it causes that all indexes for the current scroll position are outside of the new buffer bound, which will cause a CPU exception in the <b>OnDraw</b>:</div><div><br></div><div><font face="Courier New, Courier, mono">void CXTPHexEdit::OnDraw(CDC* pDC)</font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; ...<br></font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; if (m_pData)</font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br></font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (m_bShowHex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (<b><font color="#669900">m_nSelStart != -1</font></b> &amp;&amp; (m_eEditMode == editHigh || m_eEditMode == editLow))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br></font></div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i = m_nTopIndex; <font color="#FF0000"><b>(i &lt; m_nLength) </b></font>&amp;&amp; (rcd.TopLeft().y &lt; height);)<br></font><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br></font></div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<b><font color="#FF0000"> TOHEX(m_pData&#091; i &#093;<em>, p);<br></em></font></b></font></div><div><em><br></em></div><div>This is the flow up to the access exception. Although <b>m_nLength</b> correctly guards the array bounds for the initial state, it actually doesn't during the <b>SetData</b>, because it refers to the "old control state".</div><div>Note: <i>during my tests I had situations where a WM_PAINT did not happen (maybe Z-ordering), so the bug did not happen. Also CPU memory protection has a granularity with a minimum block size (4K, AFAIK), so the invalid access may not cause the exception in a 100% reproducible case. But the logic above has a clear flaw.</i><br></div><div><br></div><div>Hope this helps.<em><br></em></div><em></em>]]>
   </description>
   <pubDate>Fri, 03 Sep 2021 04:27:08 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78223&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78223</guid>
  </item> 
  <item>
   <title><![CDATA[[SOLVED]CXTPHexEdit crash when replacing Data buff : Hello,Unfortunately it is not...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78222&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78222</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=9012">agontarenko</a><br /><strong>Subject:</strong> 24202<br /><strong>Posted:</strong> 03 September 2021 at 3:57am<br /><br /><div>Hello,<br><br>Unfortunately it is not clear what exactly is going wrong. Can you please provide more detailed information.<br>If it cannot be re-produced in any of our sample applications provided I would appreciate you sending a sample application so that we could debug it.<br><br>Regards,<br>Artem Gontarenko &nbsp;              </div>]]>
   </description>
   <pubDate>Fri, 03 Sep 2021 03:57:31 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78222&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78222</guid>
  </item> 
  <item>
   <title><![CDATA[[SOLVED]CXTPHexEdit crash when replacing Data buff : Hi,I had a interesting scenario...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78220&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78220</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=9501">grumat</a><br /><strong>Subject:</strong> 24202<br /><strong>Posted:</strong> 02 September 2021 at 4:19am<br /><br /><div>Hi,</div><div><br></div><div>I had a interesting scenario here:</div><div><ul><li>An instantiated control displaying a 60K buffer.</li><li>Users scrolls up to the end of buffer and puts the cursor on the last position</li><li>User commands reload data</li><li>Crash inside<font face="Courier New, Courier, mono"> CXTPHexEdit::OnDraw()</font>.</li></ul></div><div><br></div><div>Reload Data does actually:</div><div><ul><li><font face="Courier New, Courier, mono">ctrl.SetData(NULL, 0)</font>;</li><li>Loads data</li><li>If data load OK: <font face="Courier New, Courier, mono">ctrl.SetData(newbuffer, newlength);</font></li></ul></div><div><br></div><div>Problem is: The first command shrinks the buffer to 0.</div><div>The current implementation of<font face="Courier New, Courier, mono"> CXTPHexEdit::SetData() </font>does:</div><div><ul><li>Replaces the buffer (<font face="Courier New, Courier, mono">m_pData</font>) to the empty size</li><li>Calls<font face="Courier New, Courier, mono"> SetSel(-1,-1)</font></li><li>Updates the indexes, including buffer bounds</li></ul></div><div><br></div><div>Issue: <b>SetSel </b>causes repaint, and <b>OnDraw </b>ends up accessing invalid memory because buffer bounds refers to the old buffer size.</div><div><br></div><div>My current fix was to command:</div><div><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; ctrl..m_nLength = 0;&nbsp;&nbsp;&nbsp; <font color="#009900">// OMG! access to internal stuff!!</font></font></div><div>before the new <b>SetData()</b>.<br></div><div><br></div><div>Surely that a definitive fix will needs more accuracy and tests, but hoping to see it on the next release.</div><div><br></div><div>Best regards,</div><div><br></div><div>M. Gruber<br></div>]]>
   </description>
   <pubDate>Thu, 02 Sep 2021 04:19:40 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=24202&amp;PID=78220&amp;title=solvedcxtphexedit-crash-when-replacing-data-buff#78220</guid>
  </item> 
 </channel>
</rss>