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

Issue/423 prevent index overflows #424

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ _None._

_None._

## 1.8.12

### Bug Fixes

- Prevent crash when unexpected indexes received in a PHAsset changeset [#423]

## 1.8.11

### Bug Fixes
Expand Down
18 changes: 13 additions & 5 deletions Pod/Classes/WPPHAssetDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance
BOOL incrementalChanges = assetsChangeDetails.hasIncrementalChanges;
// Capture removed, changed, and moved indexes before fetching results for incremental chaanges.
// The adjustedIndex depends on the *old* asset count.
NSIndexSet *removedIndexes = [self adjustedIndexesForIndexSet:assetsChangeDetails.removedIndexes];
NSIndexSet *changedIndexes = [self adjustedIndexesForIndexSet:assetsChangeDetails.changedIndexes];
NSInteger oldCount = assetsChangeDetails.fetchResultBeforeChanges.count;
NSIndexSet *removedIndexes = [self adjustedIndexesForIndexSet:assetsChangeDetails.removedIndexes forCount:oldCount];
NSIndexSet *changedIndexes = [self adjustedIndexesForIndexSet:assetsChangeDetails.changedIndexes forCount:oldCount];
NSMutableArray *moves = [NSMutableArray array];
if (assetsChangeDetails.hasMoves) {
[assetsChangeDetails enumerateMovesWithBlock:^(NSUInteger fromIndex, NSUInteger toIndex) {
Expand Down Expand Up @@ -360,7 +361,11 @@ - (NSInteger)adjustedIndexForIndex:(NSInteger)index forCount:(NSInteger)count
// Adjust the index so items are returned in reverse order.
// We do this, rather than specifying the sort order in PHFetchOptions,
// to preserve the sort order of assets in the Photos app (only in reverse).
return (count - 1) - index;
if (index < count) {
return (count - 1) - index;
} else {
@throw NSRangeException;
}
}

- (NSIndexSet *)adjustedIndexesForIndexSet:(NSIndexSet *)indexes
Expand All @@ -373,8 +378,11 @@ - (NSIndexSet *)adjustedIndexesForIndexSet:(NSIndexSet *)indexes forCount:(NSInt
{
NSMutableIndexSet *adjustedSet = [NSMutableIndexSet new];
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
if (idx != NSNotFound) {
[adjustedSet addIndex:[self adjustedIndexForIndex:idx forCount: count]];
if (idx < count) {
NSInteger adjustedIndex = [self adjustedIndexForIndex:idx forCount: count];
if (adjustedIndex < NSNotFound) {
[adjustedSet addIndex:adjustedIndex];
}
}
}];

Expand Down
2 changes: 1 addition & 1 deletion WPMediaPicker.podspec
Copy link
Contributor

@AliSoftware AliSoftware Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ You need to run bundle exec pod install in the Example project to also update its Podfile.lock so it accounts for that version bump

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Pod::Spec.new do |s|
s.name = 'WPMediaPicker'
s.version = '1.8.11'
s.version = '1.8.12'

s.summary = 'WPMediaPicker is an iOS controller that allows capture and picking of media assets.'
s.description = <<-DESC
Expand Down