跳至主要内容

a debug experience about overflow

For a request of a teacher, I need to debug a project finished in 2001. It's a typical overflow problem when seeing it. The program is an image compressor, but especially for remote sensing images.
The symptom is that when the width and height of image both exceed some value above 16000, the compressed result is not right. When decompress the result to restore the uncompressed format, it can't be opened.

First, I try to verify the data field is right, if it does, then the most probable taken place should be the tag field in field. Using Photoshop to read as a RAW format, the image is correctly shown, luckily! But tring to find the wrong tag require careful and thorough work. Comparing the problem image and original image, I trace the tag field directly in hex mode, two tag field is different in sixteen. the offset and bytecount is very strange. Then, I can confirm that the overflow must have happened in the related code. Of course I can't imagine that 16384 equals 2^14, because the notorious overflow point is freqently happened at 2^8, 2^16 and 2^32. But when I find the shift left operation, I know I find it. There is a shift left operation which shift 2 bits, when the width and height exceeds 2^14, this operation leads to overflow.

Except the corrections above, there still another place should correct - a short integer. We still need more considerations when design our programs, and predict the values it possibly take. In this case, the coder didn't foresee that the width and height can taken such large value, but he forgot the remote sensing image did have this kind of dimension.

评论

此博客中的热门博文

反转剧

这两天明显感到天气转冷,呱呱的家里也已经下起了大雪,南京则是阴冷潮湿,让人没有了出行的欲望。没想到躲在被子里看反转剧也成了度过寒冬的一剂良药。在PPLive越来越让人失望的时候,PPStream横空出世,虽然广告仍是少不了的主题,但从视频质量和播放连续性上来说都超过PPLive,实为居家必备之良品(由此可见,新事物一定会战胜旧事物......)。韩国的反转剧最近似乎比较流行,称之为反转剧就在于其结果总是让人出乎意料,不合常理,其间又不乏各种搞怪搞笑的镜头,各种当红帅哥美女也一定让DDMM们爱不释手,20~30分钟一集的剧情一改韩剧拖沓的风貌,想看就看,容易切入。 反转剧,今天你看了吗?

biblioscape, endnote, no, none of them

endnote在与word2003搭配时经常占据严重的CPU,非常不好用。今天听说biblioscape好,下之,唉,高兴的日子总是那么短暂,BUG一堆。它只支持rtf格式的转换,在word里format时,还要转为rtf格式后再转回来。甚至在重复转换过程中也产生了不一致,可能它在RTF和DOC之间的转换没有那么精确吧。好想用latex排,不过时间紧迫,现在懒得去学了。 都不用了,还是手工输入参考文献罢了。也许,open office?下一个先。

羊头与狗肉?

昨天买了一个路由器, 顺带两根网线。我非常自信地跟售货员说:我要两根交叉线!因为在网络里要把路由器当作一台计算机,计算机与Hub,交换机相连时用直通线,与路由器则要交叉线,这可是在IP Training里的,难道有错?售货员非常不屑地望着我:你是要接路由器吧?我说是啊,她说:那就得用直通线。噢,My God,理论与实际有这么大的差距么? 半信半疑地拿回家,开始装东东,ping通了路由器,证明售货员是对的。进入路由器的设置,被一堆设置弄得云里雾里,捣鼓了半天,感觉这不像是路由器,更像一个混血产品:宽带自动拨号+DHCP服务+防火墙+静态路由。Oh My,我倒宁愿认为这是个交换机而已,在一个交换机才50来块钱,加点东东就到近100块了。买的是羊头还是狗肉?我不知道。 P.S. 昨天中午送走了老妈三人组,在车开的那一刻,老妈竟隔着窗户奇迹般地来了几个飞吻,这让我和呱都乐开了,也免去了离别的伤感。但是回到家,原来热热闹闹的屋子变得冷冷清清,孤单地,我们再次上路。