Typical bug analysis of Oracle character garbled and data out-of-bounds access

Source: Internet
Author: User

Typical bug Analysis of Oracle character garbled and data out-of-bounds access

Preface: As party B, we found two strange bugs in the acceptance stage of party A's customers. Here's a detailed description of the source of the problem, the root cause of the problem, the solution, and how to avoid it.
First, bug1:oracle read and write characters garbled. 1. Source of the problemThe Oracle database listener http://blog.csdn.net/laoyang360/article/details/46524519 needs to obtain the most recently inserted Chinese category characters to determine the classification. One-step debugging found that each received is garbled.
2. Root cause of problem
Inconsistent encoding format is the result.
3. SolutionsThe first step: To view the encoding format of Oracle itself, you can use the commandSelect Userenv (' language ') from dual; After reviewing it, we know that many common Oracle uses simplified Chinese_china. ZHS16GBK encoded format. The second step: Check the encoding format used by the daemon, the background program reads and writes the Orcle database through OTL. The setting environment variable putenv () is used to write the nls_lang=simplified Chinese_china. Al32utf8, also known as the UTF-8 encoding format.
The third step: because the Oracle encoding format is fixed, only the background program can be modified to write environment variables in the format implified Chinese_china. ZHS16GBK encoded format. Fourth step: Look at the encoding format used by the compilation tool VS2010, we know: VC6.0 default ANSI encoding, and VS2010 default Unicode encoding. Unicode encoding and GBK encoding format are inconsistent and need to be converted . Fifth step: Check for a long time, finally through the conversion interface UTF82GBK () and Gbk2utf8 () to complete the format conversion. that is to say: Read data from the database, you need to call Gbk2utf8 () for format conversion in order to display normally under VS2010. Similarly, writing data to a database requires a call to the UTF82GBK () interface for conversion to ensure that the write to Oracle does not show garbled characters. and, the foreground program unified for UTF8 code, unified conversion to ensure that no garbled. As for the relationship between Utf8 and Unicode (in a word, UTF8 is an encoding method for encoding Unicode character sets.) See the discussion: http://www.zhihu.com/question/23374078


4. How to avoid1) The earliest design time, set the database encoding format, the owner of each module in accordance with the unified format for processing. 2) Different compiler result in different encoding format, we need to unify the interface to convert. The implementation interface can be found as follows: http://blog.csdn.net/p569354158/article/details/6567175

Second, Bug2: overflow, data out of bounds. 1. Source of the problemAfter a program performs 500 tasks frequently, the page cannot display the returned data. From the data displayed on the interface, the serial number for 67138,67139,63140 cannot be displayed. But the small ordinal 69,70 can display the corresponding return data normally.
2. Root cause of problemData out-of-bounds access, possibly taking 2 bytes unsigned short storage somewhere in the program (Maximum range: 0-2 of 16 power-1, i.e.: 0-65535). The question is how to discover: the first step: guessing data out of bounds with the number 67138, Reason: 67138>65535. and 69,70 less than 65535 of the display is normal. The second step: Database storage number and program log number one by one contrast. Check that: Oracle corresponding database table first inbound ordinal number is 67138, such as greater than 65535 value, but the second time the program returns the inserted result table becomes 1618 ordinal value, and the ordinal number is not pointid, but TaskID or SystemID, That is, an initial assertion that a cross-border visit occurred. Step Three:study why this number needs to be unique in the database? and the relevant design staff phone confirmation. Because late-stage program requirements deviate from the earliest designs, it seems to me that there is absolutely no need to use unique values. Just ensure that each task is issued only. Because the unique task number is indexed by TaskID in our program, the node number of Pointid is a level two index. The program uses the query table also, the first level index after the level two index. In the database, the sequence sequence is used to increment the unique value, and the maximum value is set very large999999999999999999999999999。 And the two-table trigger trigger all call this sequence, also said that the program's frequent task assignment, frequent execution, a few weeks or months can easily exceed the 65535 ordinal value. In summary, an out-of-bounds access in the basic Judgment program causes the display exception.
3. Solutions1) The situation is anxious: to take a simple evasion scheme: Update sequence sequence current value, the current value has been checked 67000, need to return to 1 to start again. But there is a knowledge that, under Sqldevelop and all the viewing tools, this value cannot be modified manually. Need to be removed after rebuilding. UseThe user must have alter any SEQUENCE in order to modify the SEQUENCE, you can alter all SEQUENCE except start, and if you want to modify the start value, you must drop SEQUENCE and re-create again. 2) The future needs to locate where the cross-border access, the type at least to unsigned int storage.
4. How to avoidDefine the variable of the ordinal type, consider its source, how to produce the minimum, the maximum, and then determine which type of variable to define.
Summary:1. Two bugs are not difficult, but all need to clarify the idea, avoid detours. The first bug is combed to 3.5h, and the second bug is time consuming 5h.
2. The second bug was weird, and when I finished 500 tasks, I suddenly didn't show the return data. The program basically does not change any logic. Think for a long time, excluding the effects of non-transmission devices, the impact of non-search programs, the final positioning and 65535 related.

2015-12-13 pm13:55 at home in front of the bed

Ming Yi World

Reprint please indicate source, original address: http://blog.csdn.net/laoyang360/article/details/50282569

If you feel this article is helpful, please click on the ' top ' support, your support is I insist on writing the most power, thank you!




Typical bug analysis of Oracle character garbled and data out-of-bounds access

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.