star-micronics / StarPRNT-SDK-iOS-Swift

StarPRNT SDK for iOS including libraries for supporting application development for Star printers.
https://www.star-m.jp/products/s_print/sdk/starprnt_sdk/manual/ios_swift/en/index.html
Other
42 stars 7 forks source link

[StarPRNTBuilderImpl setPageMode:] + 49 Fatal Exception #23

Closed amcalgates closed 1 year ago

amcalgates commented 1 year ago

Description

[StarPRNTBuilderImpl setPageMode:] + 49 is crashing with fatal exception

*** -[NSConcreteMutableData subdataWithRange:]: range {3, 18446744073709551613} causes integer overflow

Trace from crash log:

Fatal Exception: NSRangeException
0  CoreFoundation                 0x9e48 __exceptionPreprocess
1  libobjc.A.dylib                0x178d8 objc_exception_throw
2  Foundation                     0x5051c -[NSConcreteData copyWithZone:]
3  Rezku-POS                      0x96b310 -[StarPRNTBuilderImpl setPageMode:] + 49 (StarPRNTBuilderImpl.m:49)
4  CoreBluetooth                  0x38d40 -[CBPeripheral handleAttributeEvent:args:attributeSelector:delegateSelector:delegateFlag:]
5  CoreBluetooth                  0x38e70 -[CBPeripheral handleCharacteristicEvent:characteristicSelector:delegateSelector:delegateFlag:]
6  CoreBluetooth                  0x35ae8 -[CBPeripheral handleMsg:args:]
7  CoreBluetooth                  0x2570 -[CBCentralManager handleMsg:args:]
8  CoreBluetooth                  0x20f0 -[CBManager xpcConnectionDidReceiveMsg:args:]
9  CoreBluetooth                  0x1fc8 __30-[CBXpcConnection _handleMsg:]_block_invoke
10 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release
11 libdispatch.dylib              0x3fdc _dispatch_client_callout
12 libdispatch.dylib              0xb694 _dispatch_lane_serial_drain
13 libdispatch.dylib              0xc214 _dispatch_lane_invoke
14 libdispatch.dylib              0xb56c _dispatch_lane_serial_drain
15 libdispatch.dylib              0xc1e0 _dispatch_lane_invoke
16 libdispatch.dylib              0x16e10 _dispatch_workloop_worker_thread
17 libsystem_pthread.dylib        0xdf8 _pthread_wqthread
18 libsystem_pthread.dylib        0xb98 start_wqthread

Your device where the bug occurs

Your printer

We are seeing this crash with a mixture of users who are using STAR Printers and users who are not. So printer model is not relevant.

Your development environment

ProductName: macOS ProductVersion: 12.5 BuildVersion: 21G72

To Reproduce

Unsure. Please see stack trace. Looks like there's a missing check on an NSRange somewhere in your SDK.

Expected behavior

SDK should not crash

Screenshots

N/A

Additional context

This seemed to start happening when we started building our app against the iOS 16 SDK.

gare-bear commented 1 year ago

@amcalgates Can you share some code showing your usage of the Page Mode function(s)? and for your non-Star users, why would any of the Star functions be referenced?

amcalgates commented 1 year ago

Hey @gare-bear - we are not calling setPageMode in our app. Per the stack trace in the OP (also pasted again below), setPageMode seems to be getting called within your SDK from CBPeripheral. Perhaps it's an operation you're performing in a CBPeripheralDelegate?

As far as I can tell, the stack trace leaves me with nothing to debug on my end.

Is StarPRNT SDK open source?

Fatal Exception: NSRangeException
0  CoreFoundation                 0x9e48 __exceptionPreprocess
1  libobjc.A.dylib                0x178d8 objc_exception_throw
2  Foundation                     0x5051c -[NSConcreteData copyWithZone:]
3  Rezku-POS                      0x96b310 -[StarPRNTBuilderImpl setPageMode:] + 49 (StarPRNTBuilderImpl.m:49)
4  CoreBluetooth                  0x38d40 -[CBPeripheral handleAttributeEvent:args:attributeSelector:delegateSelector:delegateFlag:]
5  CoreBluetooth                  0x38e70 -[CBPeripheral handleCharacteristicEvent:characteristicSelector:delegateSelector:delegateFlag:]
6  CoreBluetooth                  0x35ae8 -[CBPeripheral handleMsg:args:]
7  CoreBluetooth                  0x2570 -[CBCentralManager handleMsg:args:]
8  CoreBluetooth                  0x20f0 -[CBManager xpcConnectionDidReceiveMsg:args:]
9  CoreBluetooth                  0x1fc8 __30-[CBXpcConnection _handleMsg:]_block_invoke
10 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release
11 libdispatch.dylib              0x3fdc _dispatch_client_callout
12 libdispatch.dylib              0xb694 _dispatch_lane_serial_drain
13 libdispatch.dylib              0xc214 _dispatch_lane_invoke
14 libdispatch.dylib              0xb56c _dispatch_lane_serial_drain
15 libdispatch.dylib              0xc1e0 _dispatch_lane_invoke
16 libdispatch.dylib              0x16e10 _dispatch_workloop_worker_thread
17 libsystem_pthread.dylib        0xdf8 _pthread_wqthread
18 libsystem_pthread.dylib        0xb98 start_wqthread
gare-bear commented 1 year ago

@amcalgates Thanks for the additional info. I understand now. You're not using Page Mode at all, yet it is causing crashes. I think that's all we need for right now.

To your other question, the core library in the StarPRNT SDK; StarIO & StarIO_Extension are not open source.

@bandit-ibayashi can you have someone from R&D look into this?

bandit-ibayashi commented 1 year ago

@amcalgates Thank you for your report.

In my confirmation, setPageMode is a non-public property setter. For the specification, if you are not using the printer's page mode, this property will still be used if you are using ISCBBuilder class.

But I have checked the internal implementation and have not been able to pinpoint the likely cause, nor have I been able to reproduce this issue in my environment.

Therefore, could you please to provide the following information?

Here is my environmental information.

Thank you for your cooperation.

amcalgates commented 1 year ago

Hey @bandit-ibayashi -

If possible, it would be appreaciated if you let us know the result of the xcodebuild -version command.

% xcodebuild -version
Xcode 14.2
Build version 14C18

Frequency of this crash

In the last week, it's occurred 290 times across 71 users.

The means of communication between the iOS device and the printer

Per my OP:

We are seeing this crash with a mixture of users who are using STAR Printers and users who are not. So printer model is not relevant.

My environment:

MacBook Pro 2021 macOS Monterey 12.5

Xcode Version 14.2 (14C18) SDK Version 16.2

I cannot reproduce the issue myself.

Since your SDK is not open source, I am trying my best to help: the stack trace says you are calling copy on an NSData object in StarPRNTBuilderImpl.m. The trace seems to think it's even on line 49 in this file.

Are you not seeing that?

amcalgates commented 1 year ago

@bandit-ibayashi and @gare-bear - thanks for your help and patience with this.

Our crash reporter, Crashlytics, must be incorrect in assigning blame to the StarPRNT SDK. I am finally able to reproduce the crash, and it's in the Magtek MTSCRA SDK we also use, not the StarPRNT SDK.

I should have been more careful before dragging you into this. We have never had issues with Star software - you guys are good at your jobs. Your SDK is one of my favorites to work with. Thanks for making a great SDK and for lending a hand with this issue.

gare-bear commented 1 year ago

@amcalgates Thanks for confirming the issue is outside of our SDK. And thanks for the kind words! We love to hear that kind of feedback!