asset library crashes application without any message in log - xcode

That's the log in organizer
ocesses
Name rpages recent_max [reason] (state)
MobileMail 1557 1557 [vm] (resume) (continuous)
MobilePhone 1479 1479 [vm] (resume) (continuous)
tccd 318 320 [vm] (daemon)
Testare 2293 2293 [vm] (frontmost) (resume)
ptpd 1350 1350 (daemon)
dataaccessd 1589 1589 (daemon)
aosnotifyd 512 512 (daemon)
mediaserverd 12077 12077 (daemon)
assetsd 1170 1170 (daemon)
wifid 773 773 (daemon)
iaptransportd 266 266 (daemon)
profiled 592 592 (daemon)
locationd 1373 1373 (daemon)
syslogd 185 185 (daemon)
SpringBoard 7838 7838
backboardd 5776 5776 (daemon)
BTServer 498 498 (daemon)
imagent 668 668 (daemon)
configd 741 741 (daemon)
lockdownd 353 353 (daemon)
powerd 192 192 (daemon)
mDNSResponder 294 294 (daemon)
fairplayd.N42 166 166 (daemon)
UserEventAgent 720 720 (daemon)
securityd 159 160 (daemon)
amfid 219 219 (daemon)
debugserver 0 0 (daemon)
syncdefaultsd 459 459 (daemon)
lockbot 475 475 (daemon)
springboardservi 0 0 (daemon)
CVMServer 89 89 (daemon)
notification_pro 161 161 (daemon)
afcd 157 157 (daemon)
filecoordination 214 214 (daemon)
distnoted 141 141 (daemon)
apsd 438 438 (daemon)
aggregated 109 109 (daemon)
networkd 215 215 (daemon)
fseventsd 277 277 (daemon)
CommCenter 1760 1760 (daemon)
notifyd 226 226 (daemon)
ReportCrash 331 333 (daemon)
**End**
No thread is highlited.
Here is the code
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(#"See Asset: %#", result);
NSLog(#"Index: %d", index);
ALAssetRepresentation *rep = result.defaultRepresentation;
NSLog(#"URL: %#", rep.url);
UIImage *image = [UIImage imageWithCGImage:rep.fullScreenImage];
[self performSelectorInBackground:#selector(selectImage:) withObject:image];
}
};
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
NSLog(#"GRUP Desc:%#",[group valueForProperty:ALAssetsGroupPropertyType]);
NSLog(#"GRUP Desc:%#",group.description);
NSNumber *type = (NSNumber *)[group valueForProperty:ALAssetsGroupPropertyType];
NSLog(#"GRUP Desc:%#",NSStringFromClass([type class]));
int tip = [type intValue];
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(#"Failure");
}];
It seems like if I don't use this line UIImage *image = [UIImage imageWithCGImage:rep.fullScreenImage]; and the line after is working enumerating
all assets. If I try to get the image or only get the metadata it crashes at some point. The problem is it crashes without XCode showing me the threads or the cause. Nothing is displayed on the left pane. Running it with the profiler shows me a steady 2MB usage of the application. It doesn't seem to have memory leaks.
I tried different approaches but still crashes without any error message.

Related

PDF Document with XObject jpg Image not displaying in Adobe Reader

Self-created PDF Document with an XObject Image. When viewing in Adobe Reader, receiving 'An Error exists on this page. Acrobat may not display the page correctly...' It is not clear exactly what's wrong with the document and wanted to see if anyone had suggestions.
When I run PDF Repair Tool on www.pdf-online.com the following errors were reported.
The file is corrupt and cannot be repaired, but possibly recovered
Errors:
3-Heights(TM) PDF repair tool, evaluation license valid until unbounded
Open file.
Analyze Objects.
Analyze Outlines.
Analyze Pages.
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x00410518 - I - A path painting operator was used on an empty path.
- File: JDCPDF02_007 (1).PDF
0x8041050F - E - The name Im1 of a xobject resource is unknown.
- File: JDCPDF02_007 (1).PDF
0x80410113 - E - The file is corrupt and cannot be repaired. Some of the contents can possibly be recovered.
- Page No.: 1
- File: JDCPDF02_007 (1).PDF
Close file.
The PDF Document contains the following code.
% Producer:
% Created: 20220826084735
% Function:
% Creator:
% Author:
1 0 obj<< /Type /Catalog /Outlines 2 0 R /Pages 3 0 R>>endobj
2 0 obj<< /Type /Outlines /Count 0>>endobj
3 0 obj<< /Type /Pages /Kids [ 4 0 R] /Count 1>>endobj
4 0 obj<< /Type /Page /Parent 3 0 R /MediaBox [ 0 0 792 612 ] /Contents 5 0 R /Resources << /ProcSet 41 0 R /Font << /F1 7 0 R /F2 8 0 R /F3 9 0 R /F4 10 0 R /F5 11 0 R /F6 12 0 R /F7 13 0 R /F8 14 0 R /F9 15 0 R /F10 16 0 R /F11 17 0 R /F12 18 0 R /F13 19 0 R /F14 20 0 R /F15 21 0 R /F16 23 0 R /F17 25 0 R /F18 27 0 R /F19 29 0 R /F20 31 0 R /F21 33 0 R /F22 35 0 R /F23 37 0 R /F24 39 0 R>>>>>>endobj
5 0 obj<< /Length 28756 >>
stream
.
.
.
q 132 0 0 132 45 140 cm /Im1 Do Q
endstream
endobj
6 0 obj<</Type/XObject/Subtype/Image /Width 200 /Height 200 /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /ASCII85Decode /Length 48032>>
stream
.
.
.
endstream
endobj
41 0 obj<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /XObject << /Image 6 0 R >> >>endobj
7 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F1 /BaseFont /Courier /Encoding /MacRomanEncoding>>endobj
8 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F2 /BaseFont /Courier-Oblique /Encoding /MacRomanEncoding>>endobj
9 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F3 /BaseFont /Courier-Bold /Encoding /MacRomanEncoding>>endobj
10 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F4 /BaseFont /Courier-BoldOblique /Encoding /MacRomanEncoding>>endobj
11 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F5 /BaseFont /Helvetica /Encoding /MacRomanEncoding>>endobj
12 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F6 /BaseFont /Helvetica-Oblique /Encoding /MacRomanEncoding>>endobj
13 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F7 /BaseFont /Helvetica-Bold /Encoding /MacRomanEncoding>>endobj
14 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F8 /BaseFont /Helvetica-BoldOblique /Encoding /MacRomanEncoding>>endobj
15 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F9 /BaseFont /Times-Roman /Encoding /MacRomanEncoding>>endobj
16 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F10 /BaseFont /Times-Italic /Encoding /MacRomanEncoding>>endobj
17 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F11 /BaseFont /Times-Bold /Encoding /MacRomanEncoding>>endobj
18 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F12 /BaseFont /Times-BoldItalic /Encoding /MacRomanEncoding>>endobj
19 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F13 /BaseFont /Symbol>>endobj
20 0 obj<< /Type /Font /Border [0 0 3] /Subtype /Type1 /Name /F14 /BaseFont /ZapfDingbats>>endobj
21 0 obj<</Type /Font /BaseFont /Helvetica /Name /F15 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 22 0 R /FirstChar 32 /LastChar 255 /Widths [ 288 288 360 552 552 888 672 192 336 336 384 576 288 336 288 288 552 552 552 552 552 552 552 552 552 552 288 288 576 576 576 552 1008 672 672 720 720 672 600 768 720 288 504 672 552 840 720 768 672 768 720 672 600 720 672 936 672 672 600 288 288 288 456 552 336 552 552 504 552 552 288 552 552 216 216 504 216 840 552 552 552 552 336 504 288 552 504 720 504 504 504 336 264 336 576 696 552 288 216 552 336 1008 552 552 336 1008 672 336 1008 288 288 288 288 216 216 336 336 600 552 1008 336 1008 504 336 936 288 288 672 288 336 552 552 552 552 264 552 336 744 360 552 576 336 744 552 408 552 336 336 336 576 528 288 336 336 360 552 840 840 840 600 672 672 672 672 672 672 1008 720 672 672 672 672 288 288 288 288 720 720 768 768 768 768 768 576 768 720 720 720 720 672 672 600 552 552 552 552 552 552 888 504 552 552 552 552 288 288 288 288 552 552 552 552 552 552 552 552 600 552 552 552 552 504 552 504 ]>>endobj
22 0 obj<</Type /FontDescriptor /FontName /Helvetica /Ascent 720 /Descent -204 /CapHeight 720 /StemV 80 /ItalicAngle 0 /MissingWidth 24 /XHeight 540 /FontBBox [0 -300 1000 700] /Flags 32>>endobj
23 0 obj<</Type /Font /BaseFont /Helvetica /Name /F16 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 24 0 R /FirstChar 32 /LastChar 255 /Widths [ 288 288 360 552 552 888 672 192 336 336 384 576 288 336 288 288 552 552 552 552 552 552 552 552 552 552 288 288 576 576 576 552 1008 672 672 720 720 672 600 768 720 288 504 672 552 840 720 768 672 768 720 672 600 720 672 936 672 672 600 288 288 288 456 552 336 552 552 504 552 552 288 552 552 216 216 504 216 840 552 552 552 552 336 504 288 552 504 720 504 504 504 336 264 336 576 696 552 288 216 552 336 1008 552 552 336 1008 672 336 1008 288 288 288 288 216 216 336 336 600 552 1008 336 1008 504 336 936 288 288 672 288 336 552 552 552 552 264 552 336 744 360 552 576 336 744 552 408 552 336 336 336 576 528 288 336 336 360 552 840 840 840 600 672 672 672 672 672 672 1008 720 672 672 672 672 288 288 288 288 720 720 768 768 768 768 768 576 768 720 720 720 720 672 672 600 552 552 552 552 552 552 888 504 552 552 552 552 288 288 288 288 552 552 552 552 552 552 552 552 600 552 552 552 552 504 552 504 ]>>endobj
24 0 obj<</Type /FontDescriptor /FontName /Helvetica /Ascent 720 /Descent -204 /CapHeight 720 /StemV 80 /ItalicAngle 0 /MissingWidth 24 /XHeight 540 /FontBBox [0 -300 1000 700] /Flags 32>>endobj
25 0 obj<</Type /Font /BaseFont /Helvetica /Name /F17 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 26 0 R /FirstChar 32 /LastChar 255 /Widths [ 288 288 360 552 552 888 672 192 336 336 384 576 288 336 288 288 552 552 552 552 552 552 552 552 552 552 288 288 576 576 576 552 1008 672 672 720 720 672 600 768 720 288 504 672 552 840 720 768 672 768 720 672 600 720 672 936 672 672 600 288 288 288 456 552 336 552 552 504 552 552 288 552 552 216 216 504 216 840 552 552 552 552 336 504 288 552 504 720 504 504 504 336 264 336 576 696 552 288 216 552 336 1008 552 552 336 1008 672 336 1008 288 288 288 288 216 216 336 336 600 552 1008 336 1008 504 336 936 288 288 672 288 336 552 552 552 552 264 552 336 744 360 552 576 336 744 552 408 552 336 336 336 576 528 288 336 336 360 552 840 840 840 600 672 672 672 672 672 672 1008 720 672 672 672 672 288 288 288 288 720 720 768 768 768 768 768 576 768 720 720 720 720 672 672 600 552 552 552 552 552 552 888 504 552 552 552 552 288 288 288 288 552 552 552 552 552 552 552 552 600 552 552 552 552 504 552 504 ]>>endobj
26 0 obj<</Type /FontDescriptor /FontName /Helvetica /Ascent 720 /Descent -204 /CapHeight 720 /StemV 80 /ItalicAngle 0 /MissingWidth 24 /XHeight 540 /FontBBox [0 -300 1000 700] /Flags 32>>endobj
27 0 obj<</Type /Font /BaseFont /Helvetica /Name /F18 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 28 0 R /FirstChar 32 /LastChar 255 /Widths [ 288 288 360 552 552 888 672 192 336 336 384 576 288 336 288 288 552 552 552 552 552 552 552 552 552 552 288 288 576 576 576 552 1008 672 672 720 720 672 600 768 720 288 504 672 552 840 720 768 672 768 720 672 600 720 672 936 672 672 600 288 288 288 456 552 336 552 552 504 552 552 288 552 552 216 216 504 216 840 552 552 552 552 336 504 288 552 504 720 504 504 504 336 264 336 576 696 552 288 216 552 336 1008 552 552 336 1008 672 336 1008 288 288 288 288 216 216 336 336 600 552 1008 336 1008 504 336 936 288 288 672 288 336 552 552 552 552 264 552 336 744 360 552 576 336 744 552 408 552 336 336 336 576 528 288 336 336 360 552 840 840 840 600 672 672 672 672 672 672 1008 720 672 672 672 672 288 288 288 288 720 720 768 768 768 768 768 576 768 720 720 720 720 672 672 600 552 552 552 552 552 552 888 504 552 552 552 552 288 288 288 288 552 552 552 552 552 552 552 552 600 552 552 552 552 504 552 504 ]>>endobj
28 0 obj<</Type /FontDescriptor /FontName /Helvetica /Ascent 720 /Descent -204 /CapHeight 720 /StemV 80 /ItalicAngle 0 /MissingWidth 24 /XHeight 540 /FontBBox [0 -300 1000 700] /Flags 32>>endobj
29 0 obj<</Type /Font /BaseFont /Arial /Name /F19 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 30 0 R /FirstChar 32 /LastChar 255 /Widths [ 280 280 360 560 560 893 667 187 333 333 387 587 280 333 280 280 560 560 560 560 560 560 560 560 560 560 280 280 587 587 587 560 1013 667 667 720 720 667 613 773 720 280 493 667 560 827 720 773 667 773 720 667 613 720 667 947 667 667 613 280 280 280 467 560 333 560 560 493 560 560 280 560 560 227 227 493 227 827 560 560 560 560 333 493 280 560 493 720 493 493 493 333 253 333 587 707 560 280 227 560 333 1000 560 560 333 1000 667 333 1000 280 280 280 280 227 227 333 333 600 560 1000 333 1000 493 333 947 280 280 667 280 333 560 560 560 560 253 560 333 733 373 560 587 333 733 547 400 547 333 333 333 573 533 280 333 333 360 560 840 840 840 613 667 667 667 667 667 667 1000 720 667 667 667 667 280 280 280 280 720 720 773 773 773 773 773 587 773 720 720 720 720 667 667 613 560 560 560 560 560 560 893 493 560 560 560 560 280 280 280 280 560 560 560 560 560 560 560 547 613 560 560 560 560 493 560 493 ]>>endobj
30 0 obj<</Type /FontDescriptor /FontName /Arial /Ascent 733 /Descent -213 /CapHeight 733 /StemV 80 /ItalicAngle 0 /MissingWidth 21 /XHeight 549 /FontBBox [0 -300 1000 700] /Flags 32>>endobj
31 0 obj<</Type /Font /BaseFont /Times-Roman /Name /F20 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 32 0 R /FirstChar 32 /LastChar 255 /Widths [ 253 333 413 493 493 827 773 187 333 333 493 560 253 333 253 280 493 493 493 493 493 493 493 493 493 493 280 280 560 560 560 440 920 720 667 667 720 613 560 720 720 333 387 720 613 893 720 720 560 720 667 560 613 720 720 947 720 720 613 333 280 333 467 493 333 440 493 440 493 440 333 493 493 280 280 493 280 773 493 493 493 493 333 387 280 493 493 720 493 493 440 480 200 480 547 707 493 253 333 493 440 1000 493 493 333 1000 560 333 893 253 253 253 253 333 333 440 440 600 493 1000 333 973 387 333 720 253 253 720 253 333 493 493 493 493 200 493 333 760 280 493 560 333 760 493 400 547 293 293 333 573 453 253 333 293 307 493 747 747 747 440 720 720 720 720 720 720 893 667 613 613 613 613 333 333 333 333 720 720 720 720 720 720 720 560 720 720 720 720 720 720 560 493 440 440 440 440 440 440 667 440 440 440 440 440 280 280 280 280 493 493 493 493 493 493 493 547 493 493 493 493 493 493 493 493 ]>>endobj
32 0 obj<</Type /FontDescriptor /FontName /Times-Roman /Ascent 693 /Descent -213 /CapHeight 693 /StemV 80 /ItalicAngle 0 /MissingWidth 19 /XHeight 519 /FontBBox [0 -300 1000 700] /Flags 34>>endobj
33 0 obj<</Type /Font /BaseFont /Times-Bold /Name /F21 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 34 0 R /FirstChar 32 /LastChar 255 /Widths [ 253 333 560 493 493 1000 827 280 333 333 493 573 253 333 253 280 493 493 493 493 493 493 493 493 493 493 333 333 573 573 573 493 933 720 667 720 720 667 613 773 773 387 493 773 667 947 720 773 613 773 720 560 667 720 720 1000 720 720 667 333 280 333 587 493 333 493 560 440 560 440 333 493 560 280 333 560 280 827 560 493 560 560 440 387 333 560 493 720 493 493 440 400 227 400 520 707 493 253 333 493 493 1000 493 493 333 1000 560 333 1000 253 253 253 253 333 333 493 493 600 493 1000 333 1000 387 333 720 253 253 720 253 333 493 493 493 493 227 493 333 747 293 493 573 333 747 493 400 547 293 293 333 573 533 253 333 293 333 493 747 747 747 493 720 720 720 720 720 720 1000 720 667 667 667 667 387 387 387 387 720 720 773 773 773 773 773 573 773 720 720 720 720 720 613 560 493 493 493 493 493 493 720 440 440 440 440 440 280 280 280 280 493 560 493 493 493 493 493 547 493 560 560 560 560 493 560 493 ]>>endobj
34 0 obj<</Type /FontDescriptor /FontName /Times-Bold /Ascent 680 /Descent -213 /CapHeight 680 /StemV 80 /ItalicAngle 0 /MissingWidth 19 /XHeight 510 /FontBBox [0 -300 1000 700] /Flags 262178 /FontWeight 700>>endobj
35 0 obj<</Type /Font /BaseFont /Times-Italic /Name /F22 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 36 0 R /FirstChar 32 /LastChar 255 /Widths [ 253 333 413 493 493 827 773 213 333 333 493 680 253 333 253 280 493 493 493 493 493 493 493 493 493 493 333 333 680 680 680 493 920 613 613 667 720 613 613 720 720 333 440 667 560 827 667 720 613 720 613 493 560 720 613 827 613 560 560 387 280 387 427 493 333 493 493 440 493 440 280 493 493 280 280 440 280 720 493 493 493 493 387 387 280 493 440 667 440 440 387 400 280 400 547 707 493 253 333 493 560 893 493 493 333 1000 493 333 947 253 253 253 253 333 333 560 560 600 493 893 333 973 387 333 667 253 253 560 253 387 493 493 493 493 280 493 333 760 280 493 680 333 760 493 400 547 293 293 333 573 520 253 333 293 307 493 747 747 747 493 613 613 613 613 613 613 893 667 613 613 613 613 333 333 333 333 720 667 720 720 720 720 720 680 720 720 720 720 720 560 613 493 493 493 493 493 493 493 667 440 440 440 440 440 280 280 280 280 493 493 493 493 493 493 493 547 493 493 493 493 493 440 493 440 ]>>endobj
36 0 obj<</Type /FontDescriptor /FontName /Times-Italic /Ascent 693 /Descent -213 /CapHeight 693 /StemV 80 /ItalicAngle -15 /MissingWidth 19 /XHeight 519 /FontBBox [0 -300 1000 700] /Flags 98>>endobj
37 0 obj<</Type /Font /BaseFont /Times-BoldItalic /Name /F23 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 38 0 R /FirstChar 32 /LastChar 255 /Widths [ 253 387 560 493 493 827 773 280 333 333 493 573 253 333 253 280 493 493 493 493 493 493 493 493 493 493 333 333 573 573 573 493 827 667 667 667 720 667 667 720 773 387 493 667 613 893 720 720 613 720 667 560 613 720 667 893 667 613 613 333 280 333 573 493 333 493 493 440 493 440 333 493 560 280 280 493 280 773 560 493 493 493 387 387 280 560 440 667 493 440 387 347 227 347 573 707 493 253 333 493 493 1000 493 493 333 1000 560 333 947 253 253 253 253 333 333 493 493 600 493 1000 333 1000 387 333 720 253 253 613 253 387 493 493 493 493 227 493 333 747 267 493 600 333 747 493 400 547 293 293 333 573 493 253 333 293 293 493 747 747 747 493 667 667 667 667 667 667 947 667 667 667 667 667 387 387 387 387 720 720 720 720 720 720 720 573 720 720 720 720 720 613 613 493 493 493 493 493 493 493 720 440 440 440 440 440 280 280 280 280 493 560 493 493 493 493 493 547 493 560 560 560 560 440 493 440 ]>>endobj
38 0 obj<</Type /FontDescriptor /FontName /Times-BoldItalic /Ascent 680 /Descent -213 /CapHeight 680 /StemV 80 /ItalicAngle -15 /MissingWidth 19 /XHeight 510 /FontBBox [0 -300 1000 700] /Flags 262242 /FontWeight 700>>endobj
39 0 obj<</Type /Font /BaseFont /MICR /Name /F24 /Subtype /TrueType /Encoding /WinAnsiEncoding /FontDescriptor 40 0 R /FirstChar 32 /LastChar 255 /Widths [ 253 387 560 493 493 827 773 280 333 333 493 573 253 333 253 280 493 493 493 493 493 493 493 493 493 493 333 333 573 573 573 493 827 667 667 667 720 667 667 720 773 387 493 667 613 893 720 720 613 720 667 560 613 720 667 893 667 613 613 333 280 333 573 493 333 493 493 440 493 440 333 493 560 280 280 493 280 773 560 493 493 493 387 387 280 560 440 667 493 440 387 347 227 347 573 707 493 253 333 493 493 1000 493 493 333 1000 560 333 947 253 253 253 253 333 333 493 493 600 493 1000 333 1000 387 333 720 253 253 613 253 387 493 493 493 493 227 493 333 747 267 493 600 333 747 493 400 547 293 293 333 573 493 253 333 293 293 493 747 747 747 493 667 667 667 667 667 667 947 667 667 667 667 667 387 387 387 387 720 720 720 720 720 720 720 573 720 720 720 720 720 613 613 493 493 493 493 493 493 493 720 440 440 440 440 440 280 280 280 280 493 560 493 493 493 493 493 547 493 560 560 560 560 440 493 440 ]>>endobj
40 0 obj<</Type /FontDescriptor /FontName /Times-Roman /Ascent 693 /Descent -213 /CapHeight 693 /StemV 80 /ItalicAngle 0 /MissingWidth 19 /XHeight 519 /FontBBox [0 -300 1000 700] /Flags 34>>endobj
42 0 obj<</Producer(FIS AddVantage Version 2021A)/CreationDate(D:20220826084736)/ModDate(D:20220826084736)/Title(VPI Function EPM Enter Programmers Mode)/Creator(FIS AddVantage Version 2021A User: E1073008)/Author(NCSINT FIS Trust & Custody)>>endobj
xref
0 43
0000000000 65535 f
0000000099 00000 n
0000000162 00000 n
0000000206 00000 n
0000000262 00000 n
0000000668 00000 n
0000029479 00000 n
0000077773 00000 n
0000077893 00000 n
0000078021 00000 n
0000078146 00000 n
0000078279 00000 n
0000078402 00000 n
0000078533 00000 n
0000078661 00000 n
0000078796 00000 n
0000078921 00000 n
0000079048 00000 n
0000079173 00000 n
0000079304 00000 n
0000079397 00000 n
0000079496 00000 n
0000080571 00000 n
0000080767 00000 n
0000081842 00000 n
0000082038 00000 n
0000083113 00000 n
0000083309 00000 n
0000084384 00000 n
0000084580 00000 n
0000085651 00000 n
0000085843 00000 n
0000086916 00000 n
0000087114 00000 n
0000088191 00000 n
0000088408 00000 n
0000089480 00000 n
0000089681 00000 n
0000090760 00000 n
0000090985 00000 n
0000092052 00000 n
0000077678 00000 n
0000092250 00000 n
trailer << /Size 44 /Root 1 0 R /Info 42 0 R >>
startxref
92501
%%EOF```
The /Im1 form needs to be declared in XObject sub-dictionary in the Pages Resources. For example:
4 0 obj
<<
/Type /Page
/Contents 5 0 R
/MediaBox [ 0 0 792 612 ]
/Parent 3 0 R
/Resources <<
/Font <<
/F1 7 0 R
% etc...
/F9 15 0 R
>>
/XObject <<
/Im1 6 0 R
>>
/ProcSet 41 0 R
>>
>>
endobj
Not that well explained in the PDF IOS-32000 Specification, but mentioned in Table 33 - Entries in a resource dictionary.
Also note that your PDF should really start with %PDF-x.y e.g. `%PDF-1.4'.

ubiattach failed with too many bad blocks

I was trying to read firmware from a NAND chip, and extract its program and data for analyse.
From online I learned, you must create an UBI device with your image file write to it, then you can mount it to your system.
Description
First I read a bin file from FLASH chip. binwalk I get this.
$ binwalk -Me Flash_data.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
771180 0xBC46C device tree image (dtb)
772444 0xBC95C device tree image (dtb)
823236 0xC8FC4 CRC32 polynomial table, little endian
2703360 0x294000 uImage header, header size: 64 bytes, header CRC: 0xF092DEF5, created: 2016-10-04 21:32:58, image size: 2773040 bytes, Data Address: 0x80008000, Entry Point: 0x80008000, data CRC: 0x365DF8B1, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "Linux-3.2.0"
2703424 0x294040 Linux kernel ARM boot executable zImage (little-endian)
2722452 0x298A94 gzip compressed data, maximum compression, from Unix, last modified: 1970-01-01 00:00:00 (null date)
8110080 0x7BC000 UBI erase count header, version: 1, EC: 0x2, VID header offset: 0x800, data offset: 0x1000
From its output files, I foun this ubi image file.
$ binwalk 7BC000.ubi
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 UBI erase count header, version: 1, EC: 0x2, VID header offset: 0x800, data offset: 0x1000
$ file 7BC000.ubi
7BC000.ubi: UBI image, version 1
Some information about NAND chip:
PageSize : 2048
SpareSize : 64
PagesPerBlock : 64
Blocks Size : 128KB + 4KB
Total Block : 2048
Device Size : 256MB + 8192KB8192KB
Bus Width : 8
Then I tried to mount it, like this:
$ sudo modprobe mtdblock
$ sudo modprobe nandsim first_id_byte=0x20 second_id_byte=0xac third_id_byte=0x00 fourth_id_byte=0x15
$ mtdinfo /dev/mtd0
mtd0
Name: NAND simulator partition 0
Type: nand
Eraseblock size: 131072 bytes, 128.0 KiB
Amount of eraseblocks: 4096 (536870912 bytes, 512.0 MiB)
Minimum input/output unit size: 2048 bytes
Sub-page size: 512 bytes
OOB size: 64 bytes
Character device major/minor: 90:0
Bad blocks are allowed: true
Device is writable: true
$ sudo flash_erase /dev/mtd0 0 0
$ cp 7BC000.ubi test_infile
$ sudo ubiformat /dev/mtd0 -O 2048 -f test_infile
ubiformat: mtd0 (nand), size 536870912 bytes (512.0 MiB), 4096 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4095 -- 100 % complete
ubiformat: 4096 eraseblocks are supposedly empty
ubiformat: error!: file "test_infile" (size 268713984 bytes) is not multiple of eraseblock size (131072 bytes)
error 0 (Success)
The size of "test_file" is 0x10044000, so I just remove the last 0x4000 bytes, and tried to ubiformat again.
$ dd if=test_infile of=test_infile_dd bs=268697600 count=1
$ sudo ubiformat /dev/mtd0 -O 2048 -f test_infile_dd
ubiformat: mtd0 (nand), size 536870912 bytes (512.0 MiB), 4096 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4095 -- 100 % complete
ubiformat: 4096 eraseblocks are supposedly empty
ubiformat: flashing eraseblock 1 -- 0 % complete ubiformat: error!: bad UBI magic 0xffffffff, should be 0x55424923
ubiformat: error!: bad EC header at eraseblock 1 of "test_infile_dd"
I did some research and found out, in this UBI image, there are many blocks, and every block contains data and OOB.
The reason last command fails because it searchs 0x55424923 at wrong position which is 0x20000, because of OOB, 0x55424923 is actually at 0x21000, so I think perhaps delete all of OOB part from "this_file_dd" might work. The bash command and test as follows.
#!/bin/bash
# ./dump.sh
# pagesize 0x20000
# oob size 0x01000
# block 1
dd if=infile of=test_infile_dd_nooob bs=$((0x20000)) count=1
declare -i i=1
# block others
while ((i<2048))
do
dd if=test_infile of=out bs=$((0x21000)) count=1 skip=$i
dd if=out of=outfile bs=$((0x20000)) count=1
cat outfile >> test_infile_dd_nooob
rm out
rm outfile
let i++
done
After remove all OOB, compare 2 file, and noticed that OOB has been remove.
$ xxd test_infile_dd | grep "5542 4923" ⏎
00000000: 5542 4923 0100 0000 0000 0000 0000 0002 UBI#............
00021000: 5542 4923 0100 0000 0000 0000 0000 0002 UBI#............
00042000: 5542 4923 0100 0000 0000 0000 0000 0001 UBI#............
00063000: 5542 4923 0100 0000 0000 0000 0000 0001 UBI#............
00084000: 5542 4923 0100 0000 0000 0000 0000 0001 UBI#............
$ xxd test_infile_dd_nooob | grep "5542 4923"
00000000: 5542 4923 0100 0000 0000 0000 0000 0002 UBI#............
00020000: 5542 4923 0100 0000 0000 0000 0000 0002 UBI#............
00040000: 5542 4923 0100 0000 0000 0000 0000 0001 UBI#............
00060000: 5542 4923 0100 0000 0000 0000 0000 0001 UBI#............
00080000: 5542 4923 0100 0000 0000 0000 0000 0001 UBI#............
Then ubiformat again, another error about bad UBI magic.
$ sudo ubiformat /dev/mtd0 -O 2048 -f test_infile_dd_nooob
ubiformat: mtd0 (nand), size 536870912 bytes (512.0 MiB), 4096 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4095 -- 100 % complete
ubiformat: 1 eraseblocks have valid erase counter, mean value is 0
ubiformat: 4095 eraseblocks are supposedly empty
ubiformat: warning!: only 1 of 4096 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: continue? (y/N) y
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: flashing eraseblock 1074 -- 54 % complete ubiformat: error!: bad UBI magic 00000000, should be 0x55424923
ubiformat: error!: bad EC header at eraseblock 1074 of "test_infile_dd_nooob"
Used ghex to fix wrong EC header in EB-1074, and ubiformat again, same block's CRC is not right.
sudo ubiformat /dev/mtd0 -O 2048 -f test_infile_dd_nooob -e 10
ubiformat: mtd0 (nand), size 536870912 bytes (512.0 MiB), 4096 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4095 -- 100 % complete
ubiformat: 1074 eraseblocks have valid erase counter, mean value is 10
ubiformat: 3022 eraseblocks are supposedly empty
ubiformat: use erase counter 10 for all eraseblocks
ubiformat: flashing eraseblock 1074 -- 54 % complete ubiformat: error!: bad CRC 0x7d72af58, should be 00000000
ubiformat: error!: bad EC header at eraseblock 1074 of "test_infile_dd_nooob"
Fix CRC and ubiformat again, enable ubi and ubiattach to mtd0, but another error occurs.
sudo ubiformat /dev/mtd0 -O 2048 -f test_infile_dd_nooob -e 10 ⏎
ubiformat: mtd0 (nand), size 536870912 bytes (512.0 MiB), 4096 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4095 -- 100 % complete
ubiformat: 1074 eraseblocks have valid erase counter, mean value is 10
ubiformat: 3022 eraseblocks are supposedly empty
ubiformat: use erase counter 10 for all eraseblocks
ubiformat: flashing eraseblock 1987 -- 100 % complete
ubiformat: formatting eraseblock 4095 -- 100 % complete
$ sudo modprobe ubi
$ sudo modprobe ubi mtd=0
$ sudo ubiattach -m 0 -O 2048
ubiattach: error!: cannot attach mtd0
error 22 (Invalid argument)
Do dmesg I found this message.
$ sudo dmesg
[ 6974.021149] 0001efa0: 00 00 00 00 00 00 00 00 10 0a 00 00 01 00 00 00 00 0a d9 d5 05 f9 20 a1 63 d7 00 00 00 02 fb d2 ...................... .c.......
[ 6974.021150] 0001efc0: ce 15 00 00 00 0d 00 00 02 00 00 00 04 00 20 00 c7 00 00 00 0d 0d 0d 00 00 00 0b 01 b8 00 03 db .............. .................
[ 6974.021151] 0001efe0: 03 9d 03 5e 03 20 02 fd 02 d8 02 93 02 4e 02 1b 01 f6 01 b8 20 00 7a 14 08 00 32 3b 81 0e 04 17 ...^. .......N...... .z...2;....
[ 6974.023703] ubi0 error: validate_ec_hdr [ubi]: node with incompatible UBI version found: this UBI version is 1, image version is 0
[ 6974.023707] ubi0 error: validate_ec_hdr [ubi]: bad EC header
[ 6974.023707] Erase counter header dump:
[ 6974.023708] magic 0x55424923
[ 6974.023708] version 0
[ 6974.023709] ec 10
[ 6974.023709] vid_hdr_offset 2048
[ 6974.023710] data_offset 4096
[ 6974.023710] image_seq 144665903
[ 6974.023711] hdr_crc 0xb574c34c
[ 6974.023711] erase counter header hexdump:
[ 6974.023713] 00000000: 55 42 49 23 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 08 00 00 00 10 00 08 9f 6d 2f 00 00 00 00 UBI#......................m/....
[ 6974.023713] 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b5 74 c3 4c .............................t.L
[ 6974.023715] CPU: 4 PID: 14955 Comm: ubiattach Tainted: G W E 5.7.0-kali1-amd64 #1 Debian 5.7.6-1kali2
[ 6974.023716] Hardware name: Dell Inc. Inspiron 7472/0GHVRJ, BIOS 1.1.6 06/14/2018
[ 6974.023716] Call Trace:
[ 6974.023722] dump_stack+0x66/0x90
[ 6974.023725] validate_ec_hdr+0x8a/0xe0 [ubi]
[ 6974.023729] ubi_io_read_ec_hdr+0x1e9/0x280 [ubi]
[ 6974.023732] ubi_attach+0x1d3/0x14c0 [ubi]
[ 6974.023736] ubi_attach_mtd_dev+0x5b3/0xd30 [ubi]
[ 6974.023741] ? __get_mtd_device+0x2c/0xa0 [mtd]
[ 6974.023743] ? _cond_resched+0x15/0x30
[ 6974.023746] ctrl_cdev_ioctl+0xda/0x1c0 [ubi]
[ 6974.023748] ksys_ioctl+0x87/0xc0
[ 6974.023749] __x64_sys_ioctl+0x16/0x20
[ 6974.023751] do_syscall_64+0x52/0x180
[ 6974.023753] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 6974.023754] RIP: 0033:0x7f3f55902c87
[ 6974.023756] Code: 00 00 00 48 8b 05 09 92 0c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d d9 91 0c 00 f7 d8 64 89 01 48
[ 6974.023756] RSP: 002b:00007ffd4fec6f88 EFLAGS: 00000206 ORIG_RAX: 0000000000000010
[ 6974.023757] RAX: ffffffffffffffda RBX: 00007ffd4fec7020 RCX: 00007f3f55902c87
[ 6974.023758] RDX: 00007ffd4fec6fb0 RSI: 0000000040186f40 RDI: 0000000000000003
[ 6974.023758] RBP: 0000000000000003 R08: 0000000000000001 R09: 0000000000000000
[ 6974.023759] R10: fffffffffffff48e R11: 0000000000000206 R12: 000055c2a393c052
[ 6974.023759] R13: 00007ffd4fec6fb0 R14: 0000000000000000 R15: 0000000000000000
[ 6974.023763] ubi0 error: ubi_io_read_ec_hdr [ubi]: validation failed for PEB 1074
[ 6974.061006] ubi0 error: ubi_attach_mtd_dev [ubi]: failed to attach mtd0, error -22
But I don't know how to solve this, so I just remove block 1074 from file.
$ dd if=test_infile_dd_nooob of=test_infile_dd_nooob_no1074_1 bs=131072 count=1074
$ dd if=test_infile_dd_nooob of=test_infile_dd_nooob_no1074_2 bs=131072 skip=1075
$ cat test_infile_dd_nooob_no1074_1 test_infile_dd_nooob_no1074_2 > test_infile_dd_nooob_no1074
Then ubiformat and attach again, but there was another error.
$ sudo ubiformat /dev/mtd0 -O 2048 -f test_infile_dd_nooob_no1074 -e 10
ubiformat: mtd0 (nand), size 536870912 bytes (512.0 MiB), 4096 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 4095 -- 100 % complete
ubiformat: 4096 eraseblocks have valid erase counter, mean value is 10
ubiformat: use erase counter 10 for all eraseblocks
ubiformat: flashing eraseblock 1986 -- 100 % complete
ubiformat: formatting eraseblock 4095 -- 100 % complete
$ sudo ubiattach -m 0 -O 2048 ⏎
ubiattach: error!: cannot attach mtd0
error 22 (Invalid argument)
Check dmesg and found this, this is where I don't know how to do, I don't know how I get so many bad blocks.
$ sudo dmesg
ubi0: scanning is finished
[ 7392.005554] ubi0 error: ubi_attach [ubi]: 1205 PEBs are corrupted and preserved
[ 7392.005554] Corrupted PEBs are: 1805 1802 1793 1678 1674 1670 1666 1662 1654 1653 1652 1649 1640 1639 1626 1625 1621 1605 1587 1586 1581 1563 1553 1540 1534 1533 1532 1531 1530 1529 1528 1527 1526 1525 1524 1523 1522 1521 1520 1519 1518 1517 1516 1515 1514 1512 1511 1510 1509 1508 1507 1506 1505 1504 1503 1502 1501 1500 1499 1498 1496 1495 1494 1493 1492 1491 1490 1489 1488 1487 1486 1485 1484 1483 1482 1481 1471 1449 1448 1447 1446 1445 1444 1441 1439 1438 1437 1436 1435 1434 1433 1432 1431 1430 1429 1428 1425 1424 1423 1422 1421 1420 1419 1418 1417 1416 1415 1414 1413 1412 1411 1410 1409 1408 1407 1406 1405 1404 1403 1402 1401 1400 1399 1398 1397 1396 1395 1394 1393 1391 1390 1389 1388 1387 1386 1385 1384 1383 1382 1381 1380 1379 1378 1377 1376 1375 1374 1373 1372 1371 1370 1369 1368 1367 1366 1365 1364 1363 1362 1361 1360 1359 1358 1357 1356 1355 1354 1353 1352 1351 1350 1349 1348 1347 1346 1345 1344 1343 1342 1341 1340 1339 1338 1337 1335 1334 1333 1332 1331 1330 1329 1328 1327 1326
[ 7392.005578] 1325 1324 1323 1322 1321 1294 1275 1274 1273 1264 1230 1223 1221 1219 1214 1211 1210 1207 1204 1203 1202 1201 1200 1199 1198 1197 1196 1195 1194 1193 1192 1191 1190 1189 1188 1187 1186 1185 1184 1183 1182 1181 1180 1179 1178 1177 1176 1175 1174 1173 1172 1165 1164 1163 1157 1147 1144 1143 1142 1141 1140 1139 1138 1137 1136 1134 1133 1132 1131 1130 1129 1128 1127 1126 1125 1124 1123 1122 1121 1120 1119 1118 1117 1116 1115 1114 1112 1111 1110 1109 1108 1106 1105 1098 1085 1053 1052 1044 1016 1003 1002 977 973 972 963 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 900 899 898 897 896 895 894 893 892 891 890 889 888 887 886 885 884 883 882 881 880 879 878 877 876 875 874 873 872 871 870 869 868 867 866 865 864 863 862 861 860 859 858 857 856 855 854 853 852 851 850 849 848 847 846 845 844 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820
[ 7392.005606] 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 785 784 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 727 726 725 724 723 722 721 720 719 718 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 668 667 666 665 664 663 662 661 660 659 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 611 610 609 608 607 606 605 604 602 601 600 599 598 597 596 595 594 593 592 591 589 588 587 586 585 584 583 582 581 580 579 578 577 576 575 574 573 572 571 570 569 568 567 566 565 564 563
[ 7392.005634] 562 561 560 559 558 557 556 554 553 552 551 550 549 548 547 546 545 544 543 541 540 539 538 537 536 535 534 533 532 531 530 529 528 527 526 525 524 523 522 521 520 519 518 517 516 515 514 513 512 511 510 509 508 507 506 505 504 503 502 501 500 498 497 496 495 494 493 492 491 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 441 440 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311 310 309 308 307 306
[ 7392.005661] 305 304 303 302 301 300 295 294 293 292 290 289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 233 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 177 176 175 174 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30
[ 7392.005690] 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2
[ 7392.005698] ubi0 error: ubi_attach.cold [ubi]: too many corrupted PEBs, refusing
[ 7392.028819] ubi0 error: ubi_attach_mtd_dev [ubi]: failed to attach mtd0, error -22
[ 7393.182325] systemd-journald[331]: /dev/kmsg buffer overrun, some messages lost.
I read the official documents, it says only in 2 senerios a block will be marked as bad. One is
when write opertion to eraseblock fails, UBI will move data from bad EB to a good EB, and do some tests so it can confirm whether bad EB is really bad; or when erase opertion have EIO error, then EB will be marked as bad block immediately. I am not sure which reason caused so much bad block.
My questions
In the progess, is my command doing wrong? If not, how to repair this UBI image so I can read its programs and data?
Is there other ways that can get programs and data from this UBI image file?
Tools and versions
Kali 2020.3
mtd-utils 2.1.1

MPICH output not printing

Problem
I'm running an executable cp2k installed on HPC cluster using mpich-3.2. The output from the executable is printed in an out file. The problem is, that there is no output in the out file after some steps are printed, but when I see the status of my job on the cluster, it turns out that it is still running. Basically, the problem is that my job is still running, but the output is not getting printed.
Script
I'm using the following job script:
#!/bin/bash
#PBS -N test
#PBS -o test.log
#PBS -j oe
#PBS -l nodes=2:ppn=20
#PBS -q mini
#PBS -l walltime=2:00:00
cd $PBS_O_WORKDIR
echo Master process running on `hostname`
echo Directory is `pwd`
echo PBS has allocated the following nodes:
echo `cat $PBS_NBODEFILE`
NPROCS=`wc -l < $PBS_NODEFILE`
echo This job has allocated $NPROCS nodes
export I_MPI_FABRICS=shm:dapl
export I_MPI_PROVIDER=psm2
export I_MPI_FALLBACK=0
export KMP_AFFINITY=verbose,scatter
export OMP_NUM_THREADS=1
export I_MPI_IFACE=ib0
echo Starting executation at `date`
EXEC="/home/arshil/software/cp2k-5.1.0/exe/local/cp2k.popt"
cp $EXEC ./cp2k
mpiexec -np $NPROCS --machinefile $PBS_NODEFILE ./cp2k -i test.inp >& out
rm cp2k
echo Finished at `date`
Error
The ouput in the out file:
SCF WAVEFUNCTION OPTIMIZATION
----------------------------------- OT ---------------------------------------
Minimizer : DIIS : direct inversion
in the iterative subspace
using 7 DIIS vectors
safer DIIS on
Preconditioner : FULL_SINGLE_INVERSE : inversion of
H + eS - 2*(Sc)(c^T*H*c+const)(Sc)^T
Precond_solver : DEFAULT
stepsize : 0.08000000 energy_gap : 0.08000000
eps_taylor : 0.10000E-15 max_taylor : 4
----------------------------------- OT ---------------------------------------
Step Update method Time Convergence Total energy Change
------------------------------------------------------------------------------
1 OT DIIS 0.80E-01 21.3 0.00002878 -8797.2068024142 -8.80E+03
2 OT DIIS 0.80E-01 10.9 0.00007114 -8797.2061897209 6.13E-04
3 OT DIIS 0.80E-01 10.8 0.00001688 -8797.2073257531 -1.14E-03
As it can be seen, there is no printing after step 3 in the output file, but the job is still running in the background. Even after the walltime is over, the output file remains the same as above. Where is the output going?
The executable cp2k is used to perform quantum chemical calculations and was installed on the cluster along with mpich-3.2. All CP2K needs is an input file with extension .inp. For my case, test.inp is the input file.
&FORCE_EVAL
METHOD Quickstep
&DFT
BASIS_SET_FILE_NAME GTH_BASIS_SETS
POTENTIAL_FILE_NAME GTH_POTENTIALS
&MGRID
NGRIDS 4
CUTOFF 380
REL_CUTOFF 60
&END MGRID
&QS
METHOD GPW
MAP_CONSISTENT
EXTRAPOLATION ASPC
EXTRAPOLATION_ORDER 3
&END QS
&SCF
MAX_SCF 1000
EPS_SCF 1.0E-5
SCF_GUESS ATOMIC
&OT
PRECONDITIONER FULL_SINGLE_INVERSE
MINIMIZER DIIS
N_DIIS 7
&END OT
&PRINT
&RESTART OFF
&END RESTART
&END PRINT
&END SCF
&XC
&XC_FUNCTIONAL PBE
&END XC_FUNCTIONAL
&vdW_POTENTIAL
DISPERSION_FUNCTIONAL PAIR_POTENTIAL
&PAIR_POTENTIAL
PARAMETER_FILE_NAME dftd3.dat
TYPE DFTD3
REFERENCE_FUNCTIONAL PBE
R_CUTOFF [angstrom] 12.3
&END PAIR_POTENTIAL
&END vdW_POTENTIAL
&END XC
&END DFT
&SUBSYS
&CELL
ABC 24.6904 24.6904 24.6904
PERIODIC XYZ
&END CELL
&KIND C
BASIS_SET TZV2P-GTH
POTENTIAL GTH-PBE-q4
&END KIND
&KIND P
BASIS_SET TZV2P-GTH
POTENTIAL GTH-PBE-q5
&END KIND
&KIND H
BASIS_SET TZV2P-GTH
POTENTIAL GTH-PBE-q1
&END KIND
&KIND O
BASIS_SET TZV2P-GTH
POTENTIAL GTH-PBE-q6
&END KIND
&KIND N
BASIS_SET TZV2P-GTH
POTENTIAL GTH-PBE-q5
&END KIND
&KIND Mg
BASIS_SET TZV2P-GTH
POTENTIAL GTH-PBE-q10
&END KIND
&COLVAR
&COORDINATION
ATOMS_FROM 41
ATOMS_TO 38
R_0 [bohr] 4.5
NN 6
ND 12
&END COORDINATION
&END COLVAR
&COLVAR
&COORDINATION
ATOMS_FROM 41
ATOMS_TO 42 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410 413 416 419 422 425 428 431 434 437 440 443 446 449 452 455 458 461 464 467 470 473 476 479 482 485 488 491 494 497 500 503 506 509 512 515 518 521 524 527 530 533 536 539 542 545 548 551 554 557 560 563 566 569 572 575 578 581 584 587 590 593 596 599 602 605 608 611 614 617 620 623 626 629 632 635 638 641 644 647 650 653 656 659 662 665 668 671 674 677 680 683 686 689 692 695 698 701 704 707 710 713 716 719 722 725 728 731 734 737 740 743 746 749 752 755 758 761 764 767 770 773 776 779 782 785 788 791 794 797 800 803 806 809 812 815 818 821 824 827 830 833 836 839 842 845 848 851 854 857 860 863 866 869 872 875 878 881 884 887 890 893 896 899 902 905 908 911 914 917 920 923 926 929 932 935 938 941 944 947 950 953 956 959 962 965 968 971 974 977 980 983 986 989 992 995 998 1001 1004 1007 1010 1013 1016 1019 1022 1025 1028 1031 1034 1037 1040 1043 1046 1049 1052 1055 1058 1061 1064 1067 1070 1073 1076 1079 1082 1085 1088 1091 1094 1097 1100 1103 1106 1109 1112 1115 1118 1121 1124 1127 1130 1133 1136 1139 1142 1145 1148 1151 1154 1157 1160 1163 1166 1169 1172 1175 1178 1181 1184 1187 1190 1193 1196 1199 1202 1205 1208 1211 1214 1217 1220 1223 1226 1229 1232 1235 1238 1241 1244 1247 1250 1253 1256 1259 1262 1265 1268 1271 1274 1277 1280 1283 1286 1289 1292 1295 1298 1301 1304 1307 1310 1313 1316 1319 1322 1325 1328 1331 1334 1337 1340 1343 1346 1349 1352 1355 1358 1361 1364 1367 1370 1373 1376 1379 1382 1385 1388 1391 1394 1397 1400 1403 1406 1409 1412 1415 1418 1421 1424 1427 1430 1433 1436 1439 1442 1445 1448 1451 1454 1457
ATOMS_TO 1460 1463 1466 1469 1472 1475 1478 1481 1484 1487 1490 1493 1496 1499 1502 1505
R_0 [bohr] 4.5
NN 6
ND 12
&END COORDINATION
&END COLVAR
&END SUBSYS
&END FORCE_EVAL
&GLOBAL
PROJECT test
RUN_TYPE MD
PRINT_LEVEL LOW
&END GLOBAL
&MOTION
&MD
ENSEMBLE NVT
STEPS 100000
TIMESTEP 0.5
TEMPERATURE 310
TEMP_TOL 100
&THERMOSTAT
&NOSE
LENGTH 3
YOSHIDA 3
TIMECON 100.0
MTS 2
&END NOSE
&END
&PRINT
&ENERGY
&EACH
MD 10
&END
&END
&PROGRAM_RUN_INFO
&EACH
MD 100
&END
&END
FORCE_LAST
&END PRINT
&END MD
&FREE_ENERGY
&METADYN
DO_HILLS
LAGRANGE .TRUE.
NT_HILLS 40
WW [kcalmol] 1
TEMPERATURE 310
TEMP_TOL 10
&METAVAR
SCALE 0.05
COLVAR 1
MASS 50
LAMBDA 2
&WALL
POSITION 0.0
TYPE QUARTIC
&QUARTIC
DIRECTION WALL_MINUS
K 10.0
&END
&END
&END METAVAR
&METAVAR
SCALE 0.05
COLVAR 2
MASS 50
LAMBDA 2
&WALL
POSITION 0.0
TYPE QUARTIC
&QUARTIC
DIRECTION WALL_MINUS
K 10.0
&END
&END
&END METAVAR
&PRINT
&COLVAR
COMMON_ITERATION_LEVELS 3
&EACH
MD 1
&END
&END
&HILLS
COMMON_ITERATION_LEVELS 3
&EACH
MD 1
&END
&END
&END
&END METADYN
&END
&PRINT
&TRAJECTORY
&EACH
MD 1
&END
&END
&VELOCITIES OFF
&END
&RESTART
&EACH
MD 20
&END
ADD_LAST NUMERIC
&END
&RESTART_HISTORY
&EACH
MD 2000
&END
&END
&END
&END MOTION
&EXT_RESTART
RESTART_FILE_NAME NVT-1.restart
RESTART_COUNTERS .FALSE.
&END
The problem in my opinion is not with the input file. It has got to do something with mpich-3.2. I would really appreciate some help.
This may be something similar going on / solutions that can be used here: Python "print" not working when embedded into MPI program It is not perfect as you are not using python however it may help.
At a basic level MPI launches many processes - but only the command that launches it has access to stdio etc. The redirect at the end of the line starting with mpiexec sends the stdout of mpiexec to a file. The output from your script is buffered by mpiexec until the processes end (either they complete or they are stopped).
Where the output is going is a good question and may require changes in test.np or some other way of shutting down (you mention you were out of wall time). I'm looking to solve the same problem - and will update this (if) I find an answer.
Also the output from different processes started by mpi can arrive in random order. I do not care about this but if you do you may need to pass the messages back to some common thread which sorts their order.

Why am I getting numbers larger than 1000 when I %1000 a number generated by 64 bit mersenne twister engine?

I'm trying to generate a zobrist key for transposition tables in my chess engine.
Here's how I'm generating the 64 bit numbers,
as show here: How to generate 64 bit random numbers?
typedef unsigned long long U64;
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_int_distribution<U64> dist(std::llround(std::pow(2,61)),
std::llround(std::pow(2,62)));
rand function:
U64 ZobristH::random64()
{
U64 ranUI = dist(mt);
return ranUI;
}
In order to try and make sure i'm generating random enough numbers I'm using a test distribution function I found online that looks like this (will later input data into excel and look at distribution):
int sampleSize = 2000;
int distArray[sampleSize];
int t = 0;
while (t < 10)
{
for (int i = 0; i < 10000; i++)
{
distArray[(int)(random64() % (sampleSize / 2))]++;
}
t++;
}
for (int i = 0; i < sampleSize; i++)
{
std::cout << distArray[i] << ", ";
}
the results I'm getting look a little something like this:
416763345, 417123246, 7913280, 7914356, 417726722, 417726718, 19, 83886102,
77332499, 14
Are these the decimal representation of binary numbers below 1000? Or am I doing something completely wrong?
Okay I did this to check out the distribution of random numbers; you can run this short program to generate a text file to look to see what values you are getting. Instead of using a function call I just used a lambda within the for loop and instead of setting the values into the array I wrote the values out to the text file before and after the post increment.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <random>
#include <functional> // may not need - included in almost all of my apps
#include <algorithm> // same as above
typedef unsigned long long U64;
int main( int argc, char** argv ) {
std::random_device rd;
std::mt19937_64 mt( rd() );
std::uniform_int_distribution<U64> dist( std::llround( std::pow( 2, 61 ) ),
std::llround( std::pow( 2, 62 ) ) );
auto lambda = [&] { return dist(mt); };
const int sampleSize = 2000;
// int distArray[sampleSize];
int t = 0;
std::ofstream file( "samples.txt" );
while ( t < 10 ) {
file << "Sample: " << (t+1) << "\n";
for ( int i = 0; i < 10000; i++ ) {
auto val = static_cast<int>( (lambda() % (sampleSize / 2)) );
file << std::setw(5) << i << ": " << std::setw(6) << val << "\t"
<< std::setw(6) << val++ << "\n";
// distArray[...]
}
file << "\n\n";
t++;
}
file.close();
/* for ( int i = 0; i < sampleSize; i++ ) {
std::cout << distArray[i] << "\n";
}*/
// Quick & Dirty Way TO Pause The Console
std::cout << "\nPress any key and enter to quit.\n";
char c;
std::cin >> c;
return 0;
}
Then check out the text file that this program generates and if you scroll through the file you will see the distributions. The first column is the value before the post increment and the second column is after. The largest possible value before the post increment that I have seen is 1,000 and after the post increment is 999. I've built and ran this for both 32 & 64 bit platform versions and have seen similar results for the distributions and that they indeed have a uniform distribution.
Sample.txt - Small Version About 1,000 Entries Out The 1st Sample Set
Sample: 1
0: 342 341
1: 517 516
2: 402 401
3: 741 740
4: 238 237
5: 557 556
6: 35 34
7: 572 571
8: 205 204
9: 353 352
10: 301 300
11: 65 64
12: 223 222
13: 647 646
14: 185 184
15: 535 534
16: 97 96
17: 843 842
18: 716 715
19: 294 293
20: 485 484
21: 648 647
22: 406 405
23: 250 249
24: 245 244
25: 915 914
26: 888 887
27: 986 985
28: 345 344
29: 493 492
30: 654 653
31: 860 859
32: 921 920
33: 526 525
34: 793 792
35: 503 502
36: 939 938
37: 802 801
38: 142 141
39: 806 805
40: 540 539
41: 778 777
42: 787 786
43: 884 883
44: 109 108
45: 842 841
46: 794 793
47: 279 278
48: 821 820
49: 112 111
50: 438 437
51: 402 401
52: 69 68
53: 396 395
54: 196 195
55: 655 654
56: 859 858
57: 674 673
58: 417 416
59: 331 330
60: 632 631
61: 210 209
62: 641 640
63: 737 736
64: 838 837
65: 592 591
66: 562 561
67: 883 882
68: 750 749
69: 726 725
70: 253 252
71: 660 659
72: 57 56
73: 401 400
74: 919 918
75: 851 850
76: 345 344
77: 25 24
78: 300 299
79: 781 780
80: 695 694
81: 220 219
82: 378 377
83: 471 470
84: 281 280
85: 945 944
86: 536 535
87: 407 406
88: 431 430
89: 745 744
90: 32 31
91: 389 388
92: 358 357
93: 582 581
94: 820 819
95: 622 621
96: 459 458
97: 233 232
98: 594 593
99: 509 508
100: 260 259
101: 152 151
102: 148 147
103: 137 136
104: 945 944
105: 244 243
106: 968 967
107: 54 53
108: 420 419
109: 58 57
110: 678 677
111: 715 714
112: 780 779
113: 834 833
114: 241 240
115: 669 668
116: 722 721
117: 608 607
118: 805 804
119: 155 154
120: 220 219
121: 520 519
122: 740 739
123: 184 183
124: 198 197
125: 247 246
126: 115 114
127: 520 519
128: 457 456
129: 864 863
130: 659 658
131: 511 510
132: 718 717
133: 119 118
134: 588 587
135: 113 112
136: 518 517
137: 164 163
138: 375 374
139: 866 865
140: 382 381
141: 526 525
142: 621 620
143: 680 679
144: 147 146
145: 712 711
146: 408 407
147: 486 485
148: 7 6
149: 203 202
150: 741 740
151: 290 289
152: 810 809
153: 960 959
154: 449 448
155: 683 682
156: 997 996
157: 454 453
158: 131 130
159: 427 426
160: 157 156
161: 3 2
162: 427 426
163: 554 553
164: 806 805
165: 228 227
166: 431 430
167: 174 173
168: 845 844
169: 121 120
170: 397 396
171: 770 769
172: 17 16
173: 761 760
174: 736 735
175: 629 628
176: 772 771
177: 417 416
178: 739 738
179: 226 225
180: 301 300
181: 217 216
182: 746 745
183: 344 343
184: 607 606
185: 927 926
186: 428 427
187: 385 384
188: 287 286
189: 537 536
190: 705 704
191: 649 648
192: 127 126
193: 252 251
194: 160 159
195: 390 389
196: 282 281
197: 66 65
198: 659 658
199: 844 843
200: 358 357
201: 360 359
202: 872 871
203: 495 494
204: 695 694
205: 988 987
206: 969 968
207: 641 640
208: 799 798
209: 30 29
210: 109 108
211: 675 674
212: 345 344
213: 309 308
214: 807 806
215: 283 282
216: 457 456
217: 193 192
218: 972 971
219: 330 329
220: 914 913
221: 508 507
222: 624 623
223: 254 253
224: 342 341
225: 69 68
226: 918 917
227: 551 550
228: 148 147
229: 645 644
230: 905 904
231: 503 502
232: 980 979
233: 881 880
234: 137 136
235: 202 201
236: 808 807
237: 988 987
238: 497 496
239: 506 505
240: 576 575
241: 671 670
242: 874 873
243: 217 216
244: 808 807
245: 741 740
246: 14 13
247: 206 205
248: 894 893
249: 180 179
250: 4 3
251: 27 26
252: 62 61
253: 203 202
254: 392 391
255: 868 867
256: 673 672
257: 881 880
258: 664 663
259: 831 830
260: 293 292
261: 916 915
262: 860 859
263: 487 486
264: 642 641
265: 161 160
266: 881 880
267: 233 232
268: 423 422
269: 12 11
270: 398 397
271: 993 992
272: 323 322
273: 878 877
274: 114 113
275: 42 41
276: 58 57
277: 398 397
278: 878 877
279: 64 63
280: 873 872
281: 841 840
282: 506 505
283: 412 411
284: 545 544
285: 887 886
286: 17 16
287: 504 503
288: 350 349
289: 772 771
290: 16 15
291: 597 596
292: 553 552
293: 25 24
294: 324 323
295: 242 241
296: 580 579
297: 479 478
298: 702 701
299: 640 639
300: 173 172
301: 918 917
302: 678 677
303: 714 713
304: 258 257
305: 97 96
306: 304 303
307: 80 79
308: 394 393
309: 940 939
310: 985 984
311: 651 650
312: 42 41
313: 179 178
314: 672 671
315: 915 914
316: 160 159
317: 332 331
318: 887 886
319: 370 369
320: 850 849
321: 730 729
322: 395 394
323: 889 888
324: 114 113
325: 505 504
326: 381 380
327: 578 577
328: 762 761
329: 896 895
330: 793 792
331: 295 294
332: 488 487
333: 599 598
334: 182 181
335: 25 24
336: 623 622
337: 396 395
338: 898 897
339: 981 980
340: 645 644
341: 806 805
342: 205 204
343: 404 403
344: 234 233
345: 36 35
346: 659 658
347: 285 284
348: 62 61
349: 608 607
350: 632 631
351: 825 824
352: 585 584
353: 685 684
354: 14 13
355: 828 827
356: 720 719
357: 871 870
358: 88 87
359: 716 715
360: 879 878
361: 650 649
362: 464 463
363: 898 897
364: 930 929
365: 194 193
366: 997 996
367: 105 104
368: 776 775
369: 398 397
370: 962 961
371: 434 433
372: 954 953
373: 548 547
374: 989 988
375: 943 942
376: 229 228
377: 866 865
378: 554 553
379: 567 566
380: 379 378
381: 564 563
382: 738 737
383: 468 467
384: 660 659
385: 693 692
386: 784 783
387: 739 738
388: 662 661
389: 474 473
390: 545 544
391: 958 957
392: 703 702
393: 316 315
394: 571 570
395: 95 94
396: 497 496
397: 672 671
398: 676 675
399: 821 820
400: 368 367
401: 7 6
402: 817 816
403: 221 220
404: 839 838
405: 578 577
406: 635 634
407: 453 452
408: 70 69
409: 764 763
410: 78 77
411: 968 967
412: 295 294
413: 483 482
414: 392 391
415: 23 22
416: 389 388
417: 678 677
418: 150 149
419: 863 862
420: 677 676
421: 676 675
422: 455 454
423: 405 404
424: 126 125
425: 753 752
426: 821 820
427: 328 327
428: 773 772
429: 596 595
430: 645 644
431: 829 828
432: 377 376
433: 444 443
434: 813 812
435: 395 394
436: 794 793
437: 641 640
438: 98 97
439: 827 826
440: 824 823
441: 681 680
442: 736 735
443: 288 287
444: 560 559
445: 781 780
446: 556 555
447: 327 326
448: 820 819
449: 859 858
450: 686 685
451: 919 918
452: 267 266
453: 128 127
454: 583 582
455: 446 445
456: 783 782
457: 712 711
458: 378 377
459: 367 366
460: 52 51
461: 316 315
462: 780 779
463: 398 397
464: 435 434
465: 788 787
466: 380 379
467: 235 234
468: 748 747
469: 429 428
470: 91 90
471: 675 674
472: 853 852
473: 674 673
474: 277 276
475: 179 178
476: 264 263
477: 511 510
478: 514 513
479: 979 978
480: 845 844
481: 728 727
482: 904 903
483: 874 873
484: 750 749
485: 659 658
486: 376 375
487: 713 712
488: 393 392
489: 538 537
490: 896 895
491: 879 878
492: 347 346
493: 819 818
494: 210 209
495: 707 706
496: 869 868
497: 319 318
498: 832 831
499: 498 497
500: 71 70
501: 290 289
502: 861 860
503: 295 294
504: 888 887
505: 515 514
506: 222 221
507: 661 660
508: 813 812
509: 969 968
510: 547 546
511: 900 899
512: 58 57
513: 805 804
514: 428 427
515: 453 452
516: 23 22
517: 969 968
518: 718 717
519: 775 774
520: 395 394
521: 521 520
522: 522 521
523: 465 464
524: 317 316
525: 216 215
526: 254 253
527: 696 695
528: 677 676
529: 21 20
530: 318 317
531: 301 300
532: 142 141
533: 877 876
534: 486 485
535: 981 980
536: 516 515
537: 254 253
538: 328 327
539: 385 384
540: 2 1
541: 405 404
542: 387 386
543: 794 793
544: 48 47
545: 641 640
546: 814 813
547: 981 980
548: 354 353
549: 281 280
550: 561 560
551: 683 682
552: 247 246
553: 739 738
554: 370 369
555: 799 798
556: 680 679
557: 915 914
558: 638 637
559: 254 253
560: 705 704
561: 320 319
562: 640 639
563: 487 486
564: 47 46
565: 852 851
566: 749 748
567: 419 418
568: 300 299
569: 507 506
570: 141 140
571: 972 971
572: 895 894
573: 988 987
574: 279 278
575: 268 267
576: 392 391
577: 530 529
578: 679 678
579: 855 854
580: 246 245
581: 645 644
582: 624 623
583: 417 416
584: 203 202
585: 30 29
586: 9 8
587: 585 584
588: 573 572
589: 471 470
590: 504 503
591: 290 289
592: 588 587
593: 230 229
594: 351 350
595: 651 650
596: 615 614
597: 502 501
598: 352 351
599: 472 471
// 600 - 699 omitted to make space to fit answer
700: 247 246
701: 894 893
702: 809 808
703: 382 381
704: 81 80
705: 574 573
706: 507 506
707: 508 507
708: 569 568
709: 947 946
710: 384 383
711: 14 13
712: 627 626
713: 951 950
714: 825 824
715: 657 656
716: 206 205
717: 598 597
718: 300 299
719: 266 265
720: 909 908
721: 206 205
722: 126 125
723: 841 840
724: 586 585
725: 348 347
726: 100 99
727: 361 360
728: 695 694
729: 556 555
730: 66 65
731: 5 4
732: 686 685
733: 488 487
734: 149 148
735: 622 621
736: 476 475
737: 488 487
738: 371 370
739: 331 330
740: 965 964
741: 141 140
742: 396 395
743: 917 916
744: 31 30
745: 924 923
746: 283 282
747: 369 368
748: 519 518
749: 830 829
750: 688 687
751: 374 373
752: 41 40
753: 418 417
754: 766 765
755: 854 853
756: 453 452
757: 521 520
758: 640 639
759: 185 184
760: 41 40
761: 125 124
762: 723 722
763: 341 340
764: 142 141
765: 754 753
766: 459 458
767: 899 898
768: 166 165
769: 374 373
770: 572 571
771: 304 303
772: 352 351
773: 235 234
774: 879 878
775: 736 735
776: 576 575
777: 56 55
778: 102 101
779: 170 169
780: 208 207
781: 135 134
782: 919 918
783: 599 598
784: 37 36
785: 997 996
786: 922 921
787: 502 501
788: 29 28
789: 173 172
790: 54 53
791: 601 600
792: 535 534
793: 64 63
794: 723 722
795: 491 490
796: 685 684
797: 58 57
798: 272 271
799: 261 260
800: 81 80
801: 149 148
802: 129 128
803: 712 711
804: 377 376
805: 151 150
806: 514 513
807: 14 13
808: 838 837
809: 347 346
810: 517 516
811: 442 441
812: 264 263
813: 883 882
814: 447 446
815: 140 139
816: 195 194
817: 841 840
818: 218 217
819: 858 857
820: 28 27
821: 222 221
822: 223 222
823: 906 905
824: 873 872
825: 492 491
826: 826 825
827: 738 737
828: 307 306
829: 185 184
830: 525 524
831: 449 448
832: 646 645
833: 686 685
834: 942 941
835: 433 432
836: 881 880
837: 824 823
838: 641 640
839: 290 289
840: 897 896
841: 4 3
842: 124 123
843: 679 678
844: 524 523
845: 424 423
846: 282 281
847: 625 624
848: 414 413
849: 647 646
850: 129 128
851: 395 394
852: 720 719
853: 318 317
854: 262 261
855: 402 401
856: 413 412
857: 139 138
858: 549 548
859: 472 471
860: 162 161
861: 605 604
862: 67 66
863: 980 979
864: 465 464
865: 912 911
866: 219 218
867: 648 647
868: 619 618
869: 331 330
870: 625 624
871: 360 359
872: 425 424
873: 935 934
874: 89 88
875: 641 640
876: 535 534
877: 404 403
878: 966 965
879: 27 26
880: 281 280
881: 637 636
882: 57 56
883: 152 151
884: 156 155
885: 813 812
886: 340 339
887: 181 180
888: 921 920
889: 306 305
890: 101 100
891: 178 177
892: 417 416
893: 845 844
894: 904 903
895: 295 294
896: 346 345
897: 654 653
898: 357 356
899: 929 928
900: 195 194
901: 499 498
902: 377 376
903: 727 726
904: 570 569
905: 853 852
906: 71 70
907: 580 579
908: 642 641
909: 889 888
910: 559 558
911: 134 133
912: 324 323
913: 120 119
914: 991 990
915: 6 5
916: 708 707
917: 347 346
918: 929 928
919: 454 453
920: 636 635
921: 218 217
922: 739 738
923: 715 714
924: 87 86
925: 782 781
926: 670 669
927: 845 844
928: 79 78
929: 730 729
930: 58 57
931: 216 215
932: 711 710
933: 898 897
934: 871 870
935: 388 387
936: 389 388
937: 944 943
938: 927 926
939: 88 87
940: 617 616
941: 940 939
942: 948 947
943: 927 926
944: 646 645
945: 125 124
946: 615 614
947: 846 845
948: 705 704
949: 998 997
950: 304 303
951: 346 345
952: 675 674
953: 783 782
954: 129 128
955: 69 68
956: 17 16
957: 646 645
958: 559 558
959: 62 61
960: 807 806
961: 571 570
962: 54 53
963: 297 296
964: 771 770
965: 972 971
966: 829 828
967: 786 785
968: 650 649
969: 101 100
970: 705 704
971: 690 689
972: 365 364
973: 304 303
974: 82 81
975: 776 775
976: 495 494
977: 586 585
978: 556 555
979: 77 76
980: 640 639
981: 161 160
982: 910 909
983: 46 45
984: 43 42
985: 162 161
986: 514 513
987: 654 653
988: 668 667
989: 126 125
990: 254 253
991: 133 132
992: 398 397
993: 993 992
994: 357 356
995: 298 297
996: 519 518
997: 904 903
998: 382 381
999: 28 27
1000: 19 18
1001: 939 938
1002: 868 867
1003: 888 887
1004: 576 575
1005: 183 182
1006: 174 173
1007: 679 678
1008: 831 830
1009: 464 463
1010: 876 875
1011: 738 737
1012: 447 446
1013: 385 384
1014: 271 270
1015: 38 37
1016: 28 27
1017: 451 450
1018: 162 161
1019: 847 846
1020: 430 429
1021: 849 848
1022: 207 206
1023: 196 195
1024: 42 41
1025: 709 708
1026: 557 556
1027: 173 172
1028: 788 787
1029: 160 159
1030: 535 534
1031: 555 554
1032: 252 251
1033: 111 110
1034: 476 475
1035: 780 779
1036: 44 43
1037: 190 189
1038: 443 442
1039: 655 654
1040: 7 6
1041: 845 844
1042: 856 855
1043: 274 273
1044: 933 932
1045: 336 335
1046: 185 184
1047: 580 579
1048: 807 806
1049: 286 285
1050: 409 408
1051: 347 346
1052: 461 460
1053: 624 623
1054: 378 377
1055: 903 902
1056: 483 482
1057: 838 837
1058: 809 808
1059: 919 918
1060: 544 543
1061: 458 457
1062: 121 120
1063: 192 191
1064: 126 125
1065: 843 842
1066: 927 926
1067: 390 389
1068: 567 566
1069: 1000 999
Entry 1069 is the first occurrence in this sample set to reach 1,000. I've ran this about a dozen times both in 32bit and 64bit modes and I did not see any value go above 1,000.
I'm not sure but I think that this line in your code is what is giving you your problem(s):
distArray[(int)(random64() % (sampleSize / 2))]++;

Sum of Rotated Integral Image (RSAT) not return sum of original pixel value

I have an image, eg, matrix A;
A= [156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 153 155 159 159 155 156 155 155 157;
155 155 155 157 156 159 152 158 156 158;
156 153 157 156 153 155 154 155 157 156;
159 159 156 158 156 159 157 161 162 157;
158 155 158 154 156 160 162 155 159 161;
155 154 157 158 160 160 159 160 158 161]
To get pixel value for RSAT(x,y),
RSAT(x,y) = RSAT(x-1,y-1) + RSAT(x-1,y+1) - RSAT(x-2,y) + I(x-1,y)+ I(x,y); where I is original image(matrixA).
Matrix B (after calculated RSAT):
[0 0 0 0 0 0 0 0 0 0 0;
0 156 159 158 155 158 156 159 158 157 158;
156 475 627 629 629 626 632 631 632 631 475;
475 943 1258 1413 1413 1418 1416 1422 1420 1265 949;
943 1574 2042 2357 2515 2518 2523 2522 2371 2053 1583;
1574 2358 2980 3456 3779 3936 3938 3786 3468 3002 2370;
2358 3291 4080 4712 5193 5514 5513 5192 4730 4096 3317;
3291 4391 5331 6129 6760 7079 7082 6763 6133 5358 4410;
4391 5646 6752 7692 8329 8637 8643 8334 7707 6766 5671;
5646 7069 8321 9266 9881 10205 10208 9906 9283 8341 7084;
7069 8634 9892 10825 11454 11768 11788 11478 10855 9918 8663]
Total sum of Region (bold region) at matrix A = 2041 .
However, sum of Region (bold region ) at matrix B= 1880. As a integral image theory, it suppose return same value as matrix A, 2041.
Here my code (matlab)
Kindly please assist me.
Thank you.
I= [156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 153 155 159 159 155 156 155 155 157;
155 155 155 157 156 159 152 158 156 158;
156 153 157 156 153 155 154 155 157 156;
159 159 156 158 156 159 157 161 162 157;
158 155 158 154 156 160 162 155 159 161;
155 154 157 158 160 160 159 160 158 161];
Dummy_Ori_Img =padarray(I,[1 1],'pre') ;
Dummy_Ori_Img2 =padarray(Dummy_Ori_Img,[0 1],'replicate','post') ;
%calculate RSAT
RSAT = zeros(size(Dummy_Ori_Img2));
[Height_Dummy,Width_Dummy]=size (Dummy_Ori_Img2);
for x =1:Height_Dummy
for y = 1:Width_Dummy
if x-2<=0 || (x-2)>Height_Dummy || y>=Width_Dummy ||y==1
RSAT1=0;
else
RSAT1= RSAT(x-2,y);
end
if x-1<=0 || y-1<=0 || (x-1)>Height_Dummy || (y-1)>Width_Dummy
RSAT2=0;
else
RSAT2=RSAT(x-1,y-1);
end
if x-1<=0 || (x-1)>Height_Dummy || (y+1)>Width_Dummy
RSAT3=0;
else
RSAT3=RSAT(x-1,y+1);
end
if x-1<=0 || y<=0 || x>Width_Dummy || y>Height_Dummy
DOI1=0;
else
DOI1=Dummy_Ori_Img(x-1,y);
end
if x<=0 || y<=0 || x>Width_Dummy || y>Height_Dummy
DOI2=0;
else
DOI2=Dummy_Ori_Img(x,y);
end
RSAT(x,y)= RSAT3 + RSAT2-RSAT1 + DOI2 + DOI1;
end
end
RSATnew = RSAT (1:size(Dummy_Ori_Img,1),1: size(Dummy_Ori_Img,2) );
outer_upright_kernel = ones (3,3);
TiltedKernel=ceil(imrotate(outer_upright_kernel,45,'bilinear','loose'));
[Height_tilt,Width_tilt]=size (TiltedKernel);
HalfTilt_x= floor(Width_tilt/2);
HalfTilt_y= floor(Height_tilt/2);
% calculate sum of region
xi=6;
yi=6;
fourpoints = [xi yi HalfTilt_x HalfTilt_y];
row_val=fourpoints(1,1);
col_val=fourpoints(1,2);
img_width=fourpoints(1,3);
img_length=fourpoints(1,4);
if row_val-1<=0 ||col_val-img_width<=0
T1to = 0;
else
T1to = RSATnew(row_val-1,col_val-img_width);
TiltOuter1 = [row_val-1,col_val-img_width];
end
if row_val-1-img_length<=0 || col_val-1<=0
T2to = 0;
else
T2to = RSATnew(row_val-1-img_length,col_val);
TiltOuter2 = [row_val-1-img_length,col_val];
end
if row_val + img_length<=0 ||col_val<=1
T3to = 0;
else
T3to = RSATnew(row_val + img_length,col_val);
TiltOuter3 = [row_val + img_length,col_val];
end
if col_val+img_width+1 <=0
T4to = 0;
else
T4to = RSATnew(row_val,col_val+img_width+1);
TiltOuter4 = [row_val,col_val+img_width+1];
end
TiltOuterSum = T2to + T3to - T1to - T4to;
Based on Lienhart(2002) (http://www.multimedia-computing.de/mediawiki/images/5/52/MRL-TR-May02-revised-Dec02.pdf),
the RSAT (x,y)= RSAT(x-1,y-1) + RSAT(x+1,y-1) - RSAT(x,y-2) + I(x,y) + I(x,y-1)
For your matrix, A
[156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 153 155 159 159 155 156 155 155 157;
155 155 155 157 156 159 152 158 156 158;
156 153 157 156 153 155 154 155 157 156;
159 159 156 158 156 159 157 161 162 157;
158 155 158 154 156 160 162 155 159 161;
155 154 157 158 160 160 159 160 158 161].
Then, RSAT of matrix A should be:
[156 159 158 155 158 156 159 158 157 158;
475 627 629 629 626 #632# 631 632 631 475;
787 1258 1413 1413 1418 1416 1422 1420 1265 791;
1099 1886 2357 2515 2518 2523 2522 2371 1895 1108;
1415 2505 #3300# 3779 3936 3938 3786 3310 #2527# 1421;
1717 3137 4237 5037 5514 5513 5034 4255 3147 1734;
2033 3757 5186 6285 6923 6924 6288 5184 3775 2040;
2355 4394 6118 7386 8004 #8012# 7385 6124 4396 2354;
2678 5030 6908 8149 8787 8784 8167 6913 5024 2674;
2988 5501 7376 8621 9245 9262 8633 7382 5508 2992]
Total sum of region (bold region in matrix A - I have altered based on the paper) is 2817. Based on RSAT, should be calculated as 8012 + 632 - 3300 - 2527 = 2817.

Resources