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

fix(handler): fix UBI PEB size calculation. #706

Merged
merged 1 commit into from
Jan 22, 2024
Merged

Conversation

qkaiser
Copy link
Contributor

@qkaiser qkaiser commented Jan 19, 2024

Computing the most frequent interval can only work if we return each and every interval value observed in a list. Returning it in a set hides the repeating interval patterns.

The get_intervals function now actually acts like numpy.diff.

Computing the most frequent interval can only work if we return each and
every interval value observed in a list. Returning it in a set hides the
repeating interval patterns.

The 'get_intervals' function now _actually_ acts like numpy.diff.
@qkaiser qkaiser added bug Something isn't working format:filesystem labels Jan 19, 2024
@qkaiser qkaiser self-assigned this Jan 19, 2024
@qkaiser
Copy link
Contributor Author

qkaiser commented Jan 19, 2024

To provide more context, here's how get_intervals is used by the UBI handler:

def _guess_peb_size(self, file: File) -> int:
        # Since we don't know the PEB size, we need to guess it. At the moment we just find the
        # most common interval between every erase block header we find in the image. This _might_
        # cause an issue if we had a blob containing multiple UBI images, with different PEB sizes.
        all_ubi_eraseblock_offsets = list(iterate_patterns(file, self._UBI_EC_HEADER))

        offset_intervals = get_intervals(all_ubi_eraseblock_offsets)
        if not offset_intervals:
            raise InvalidInputFormat

        return statistics.mode(offset_intervals)

Copy link
Contributor

@e3krisztian e3krisztian left a comment

Choose a reason for hiding this comment

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

Nice catch! :)

@qkaiser qkaiser merged commit 4b1ce6c into main Jan 22, 2024
17 checks passed
@qkaiser qkaiser deleted the fix-ubi-handler branch January 22, 2024 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working format:filesystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants