Skip to content

NSInvalidArgumentException when LinearGradient's parseReference is called on iOS #2854

@luisfelipeas5

Description

@luisfelipeas5

Description

Only on iOS, parseReference method from RNSVGLinearGradient is throwing the following exception:

NSInvalidArgumentException - *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]

The error was happening in production and our team couldn't reproduce the exception. We supposed that one of our svg files are missing some of the x1, x2, y1 or y2 attributes, but force to simulated that didn't cause a crash. Also, we try to render only our svgs with gradient multiple times and nothing happened. We had some repeated tag ids and some <stop /> tags without offset, but forcing to render these svgs also didn't force the exception.

We end up:

  RNSVGLength *x1 = self.x1 ?: [RCTConvert RNSVGLength:@"0"];
  RNSVGLength *y1 = self.y1 ?: [RCTConvert RNSVGLength:@"0"];
  RNSVGLength *x2 = self.x2 ?: [RCTConvert RNSVGLength:@"0"];
  RNSVGLength *y2 = self.y2 ?: [RCTConvert RNSVGLength:@"0"];

  NSArray<RNSVGLength *> *points = @[ x1, y1, x2, y2 ];

We end up using the fork and publishing our app with the simplified svgs, and this exception is not being thrown until now: the new version has already 136 sessions with 0 crashes, and the old one had 2.94K sessions with 497 crashes of this type.

So we doesn't identify the svg with the problem yet.

What is happening now: the app is crashing after calling parseReference of LinearGradient with nil properties
Expected: doesn't crash the app and log a warning if this happen

Stacktrace:

      Fatal Exception: NSInvalidArgumentException

0 CoreFoundation 0x940c __exceptionPreprocess
1 libobjc.A.dylib 0x15c28 objc_exception_throw
2 CoreFoundation 0x1983fc -[__NSCFString characterAtIndex:].cold.1
3 CoreFoundation 0x195238 -[__NSPlaceholderArray initWithCapacity:].cold.1
4 CoreFoundation 0x4758 -[__NSPlaceholderArray initWithObjects:count:]
5 CoreFoundation 0x5958 +[NSArray arrayWithObjects:count:]
6 daki 0xe0c3c4 -[RNSVGLinearGradient parseReference] + 184 (RNSVGLinearGradient.mm:184)
7 daki 0xe017a0 __27-[RNSVGDefs parseReference]_block_invoke + 59 (RNSVGDefs.mm:59)
8 daki 0xe0faa8 -[RNSVGNode traverseSubviews:] + 608 (RNSVGNode.mm:608)
9 daki 0xe0a208 _28-[RNSVGGroup parseReference]block_invoke + 290 (RNSVGGroup.mm:290)
10 daki 0xe0faa8 -[RNSVGNode traverseSubviews:] + 608 (RNSVGNode.mm:608)
11 daki 0xe0a17c -[RNSVGGroup parseReference] + 291 (RNSVGGroup.mm:291)
12 daki 0xe1ae28 -[RNSVGSvgView drawToContext:withRect:] + 311 (RNSVGSvgView.mm:311)
13 daki 0xe1afb0 -[RNSVGSvgView drawRect:] + 332 (RNSVGSvgView.mm:332)
14 UIKitCore 0x197054 -[UIView(CALayerDelegate) drawLayer:inContext:]
15 QuartzCore 0x1d0e8 CABackingStoreUpdate

16 QuartzCore 0x8edb8 invocation function for block in CA::Layer::display
()
17 QuartzCore 0x1c7a8 -[CALayer _display]
18 QuartzCore 0x1c034 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
19 QuartzCore 0x2c9f0 CA::Context::commit_transaction(CA::Transaction*, double, double*)
20 QuartzCore 0x59dc0 CA::Transaction::commit()
21 QuartzCore 0x44dbc CA::Transaction::flush_as_runloop_observer(bool)
22 CoreFoundation 0x898e8 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
23 CoreFoundation 0x1951c __CFRunLoopDoObservers
24 CoreFoundation 0x75214 __CFRunLoopRun
25 CoreFoundation 0x79d20 CFRunLoopRunSpecific
26 GraphicsServices 0x1998 GSEventRunModal
27 UIKitCore 0x37134c -[UIApplication _run]
28 UIKitCore 0x370fc4 UIApplicationMain

Steps to reproduce

  1. Render the svg with linear gradient with "corrupted svg tags" (with invalid x1, x2, y1 or y2 values)
  2. Force to call parseReference of RNSVGLinearGradient for this svg

Snack or a link to a repository

https://github.com/JOKR-Services/react-native-svg/pull/3/changes

SVG version

15.12.0

React Native version

0.77.0

Platforms

iOS

JavaScript runtime

None

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Release app & production bundle

Device

Real device

Device model

iPhone (multiple models and iOS versions)

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Missing reproThis issue need minimum repro scenario

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions