Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError (RangeError (byteOffset) ... error on iOS #656

Open
1 task done
JaffaKetchup opened this issue Jul 20, 2024 · 6 comments
Open
1 task done

IndexError (RangeError (byteOffset) ... error on iOS #656

JaffaKetchup opened this issue Jul 20, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@JaffaKetchup
Copy link

This report is based on a 3rd party private report to https://github.com/JaffaKetchup/flutter_map_tile_caching. As much info is supplied as is known, let me know if more is required!

Is there an existing issue?

Build info

  • objectbox version: 4.0.1
  • Flutter/Dart version: unsure
  • Build OS: 2020 Mac Mini M1
  • Deployment OS or device: iOS 17.4 (iPhone 11 & SE)

Steps to reproduce

FMTC allows users to export parts of the database, then re-import them. There is practically no difference to a standard read/write operation though. Note that an import is not the same as a complete replacement of the existing 'data.mdb' file with a new one. Both databases are open at the same time, and the needed data is transferred manually between them.

When importing the attached database into the OP's app, or the FMTC example app (https://github.com/JaffaKetchup/flutter_map_tile_caching), the following error is thrown, on iOS only:

image (1)

Raw ObjectBox file: https://drive.google.com/file/d/133UXCBJDydiN_kYlbQjrHYygdK16S82V/view?usp=sharing (do not distribute)

FMTC compatible file (contains the ObjectBox file, but with extra footer information): https://drive.google.com/file/d/1x5JoqnTvqD_QRr2bpIVcYuh6tQKt3KXu/view?usp=sharing (do not distribute)

To reproduce with the example app, clone the repo, run the example app, then follow the screenshots:

step1 step2

Select to import the FMTC compatible file, choose any conflict resolution mode (skip/merge/etc.), then tap the FAB.

Expected behavior

The same behaviour should occur on the iOS platform as on other platforms: that is, the import operation succeeds without error.

Actual behavior

The error in the screenshot is thrown.

Code

It is difficult to provide an MRE. The import algorithm can be found at https://github.com/JaffaKetchup/flutter_map_tile_caching/blob/9268675e19d246da2a9bb298aa00812e09c5891e/lib/src/backend/impls/objectbox/backend/internal_workers/standard/worker.dart#L874-L1279, but it is somewhat context dependent (note, for example, 'store' in FMTC terminology is not the same as an ObjectBox 'store'). The code runs within an isolate.

Logs, stack traces

As well as the screenshot above, see these screenshots as well - not sure if they're useful or not:

image (2)

image (3)

@greenrobot-team
Copy link
Member

Thanks for reporting!

Some basics: it looks like this happens when reading url from ObjectBoxTile:

  @Index()
  @Unique(onConflict: ConflictStrategy.replace)
  String url;

Then FlatBuffers errors because the byte offset is too large.

I tried to run the example app, but it appears it does not support iOS or macOS? Had to run flutter create . to add required files. Then flutter run on an iOS simulator worked.

I dragged the fmtc file onto the simulator and tried to select it. However, it is grayed out. Is there something I am missing?

Anyhow, I analyzed the data.mdb file with Admin and the url strings seem to be around 30 characters. So unlikely related to length. Will have to look at this further.

@greenrobot-team greenrobot-team self-assigned this Jul 23, 2024
@Soap-141
Copy link

Soap-141 commented Jul 23, 2024

Yes, you'll need to change some things in the widget so the file is not grayed out.

image

@JaffaKetchup
Copy link
Author

JaffaKetchup commented Jul 23, 2024

I tried to run the example app, but it appears it does not support iOS or macOS? Had to run flutter create . to add required files. Then flutter run on an iOS simulator worked.

I don't have any Apple devices, so I didn't include any of those platform files.

As @Soap-141 said (thanks :)), the file's probably greyed out because the file picker stuff is quite hard to get right across all platforms. Hopefully that works.

@Soap-141
Copy link

Soap-141 commented Aug 6, 2024

Hello, any update on this? Can I provide anything else?

@greenrobot-team
Copy link
Member

OK, finally had time to try to reproduce this again. @Soap-141 thanks, your suggestion allowed me to import the file!

However, running a few times with flutter run using the iOS simulator I can only get a different exception:

[ERROR:flutter/runtime/dart_isolate.cc(1291)] Unhandled exception:
Bad state: Cannot add event after closing
#0      _StreamController.addError (dart:async/stream_controller.dart:612:24)
#1      Query._streamIsolate.<anonymous closure> (package:objectbox/src/native/query/query.dart:1403:28)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#5      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#6      _StreamController._add (dart:async/stream_controller.dart:658:7)
#7      _StreamController.add (dart:async/stream_controller.dart:606:5)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

And when running through Visual Studio Code (with "Uncaught Exceptions" enabled) I always get Error._throw (in flutter/bin/cache/pkg/sky_engine/lib/_internal/vm/lib/errors_patch.dart) and can't load additional stack frames.

Next week at the earliest I'll try to have a look at why FlatBuffers might throw the above exception, maybe that gives a useful hint.

@Soap-141
Copy link

Soap-141 commented Aug 7, 2024

@greenrobot-team Thanks! Yes I understand, I also had a hard time debugging iOS on my Mac using VS Code and Xcode, by playing around with exception settings and breakpoints I managed to have multiple exceptions and errors similar to this, you are on the right path.

Feel free to let me know if I can help more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants