{"id":111232,"date":"2025-05-30T07:00:00","date_gmt":"2025-05-30T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111232"},"modified":"2025-05-30T11:42:08","modified_gmt":"2025-05-30T18:42:08","slug":"20250530-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250530-00\/?p=111232","title":{"rendered":"Using an oracle to see where your code is producing the wrong output"},"content":{"rendered":"<p>You may find yourself trying to generate some output, and the output is wrong, where &#8220;wrong&#8221; means &#8220;is not accepted by whatever program consumes that output.&#8221; It is often the case that you have a reference implementation, which I somewhat whimsically call an &#8220;oracle&#8221;, that is known to produce acceptable output. In that case, you can use that reference implementation to check your implementation.\u00b9<\/p>\n<p>Give your implementation and the reference implementation the same input, and see if they produce the same output. For binary formats, you can use a binary file viewer program. In a pinch, you can use the Windows <code>comp.exe<\/code> or <code>fc.exe \/b<\/code> programs. The files will not be identical,\u00b2 and the tool will tell you where they differ. Work backward from that file offset to your program to see why your program chose to write the wrong data at that point. (Maybe you forgot to open the output file in binary mode?)<\/p>\n<p>\u00b9 I used a variation of this technique some time ago when <a title=\"Standing on the shoulders of giants: Let the compiler tell you what the ABI is\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20220112-00\/?p=106150\"> reverse-engineered the calling convention for various historical CPU architectures<\/a>.<\/p>\n<p>\u00b2 If the file contents are identical at the byte level, yet one is accepted and the other is rejected, then the problem is not in the file contents. Maybe there is file metadata that does not match, like the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mark_of_the_Web\"> Mark of the Web<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If there is a reference implementation, then use it as a check.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-111232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If there is a reference implementation, then use it as a check.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=111232"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111232\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=111232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}