跳至主要内容

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分钟一集的剧情一改韩剧拖沓的风貌,想看就看,容易切入。 反转剧,今天你看了吗?

from cpp to java

when i start to study java with a cpp background, i find it is very difficult to convert my mind. i always think how some features in cpp was implemented in java, this give me a little reject to java language. though java is born from c, i think they still have different applicable domains, so try to study both is good for me, and java is a pure OO language, i believe it will give me a better understanding on OOD.

Linking

We know the process of building programs are divided into two parts, compiling and linking. Linking is a process that combine different part of codes and data into one executable program. Here is a general picture: Preprocessing -> Compiling -> Assembling -> Linking A linker mainly does two tasks: symbol resolution, and relocation. Symbol resolution relates every symbols referenced in the target object file (both code and data) to their definition. Relocation generate an absolute address for every symbols according their relative addresses, since code starts from address 0x00 after assembling. Every object file will contain their own symbol tables. There are symbols defined in and not in the current object file. Function and initialized variables are strong symbols, and uninitialized variables are weak symbols. Rules for symbol resolution in Unix linker are defined as followes: Rule.1 Only one strong symbol is allowed, otherwise is a linker err...