<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Thank you for the suggestion! I am still not sure about the correct way to communicate on mailing-list.
<div><br /></div>
<div>But I have figured out the problem which is caused by arithmetic overflow. I was using Word8 to parse the packet length and presumed the packet length would be larger than 46. The subtraction of 47 from the Word8 packet length gave the largest number Word8 could represent, which definitely exceeds the length of the whole file. </div>
</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
Regards,
<div>Qingbo Liu</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On Feb 26, 2018, 02:41 -0500, Robin Palotai <palotai.robin@gmail.com>, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div dir="ltr">
<div>[-list]<br />
<br /></div>
FYI Given the lack of responses, I think more context would help. For example github / gist link to code, minimal case to reproduce.<br /></div>
<div class="gmail_extra"><br />
<div class="gmail_quote">2018-02-23 16:59 GMT+01:00 Quentin Liu <span dir="ltr"><<a href="mailto:quentin.liu.0415@gmail.com" target="_blank">quentin.liu.0415@gmail.com</a>></span>:<br />
<blockquote class="gmail_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">Hi,</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51);min-height:16px"><br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">I am using Data.Binary to decode binary files and found that the `runGet` function would throw an exception “not enough bytes” even though it has not consumed all the input.</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51);min-height:16px"><br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">Specifically, in the loop I am repeatedly trying to parse the binary file until it has consumed all the input</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"><br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"> parsePPackets xs = do<br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"> empty <- isEmpty</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"> if empty</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"> then return xs</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"> else do p <- parseB6034</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)"> parsePPackets (p:xs)</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51);min-height:16px"><br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">When I try to run this function with `runGet`, the exception “Data.Binary.Get.runGet at position 3293603: not enough bytes” would be thrown, while the total length of input is 5864230, a number significantly larger. The function `parseB6034` consumes no more than 250 bytes in each round. In addition, the `parsePPackets` works well when fed with a small amount of data.</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51);min-height:16px"><br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">Is it the problem of my code or an error with the package binary? The ByteString fed into `runGet` is lazy ByteString, as required by `runGet` function.</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51);min-height:16px"><br /></p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">Best Regards,</p>
<p style="margin:0px;font-stretch:normal;line-height:normal;font-family:"Helvetica Neue";color:rgb(51,51,51)">Qingbo Liu</p>
</div>
</div>
<br />
______________________________<wbr />_________________<br />
Haskell-Cafe mailing list<br />
To (un)subscribe, modify options or view archives go to:<br />
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr />bin/mailman/listinfo/haskell-<wbr />cafe</a><br />
Only members subscribed via the mailman list are allowed to post.<br /></blockquote>
</div>
<br /></div>
</blockquote>
</div>
</body>
</html>