package defpackage;

import java.io.DataInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import org.tukaani.xz.CorruptedInputException;
import org.tukaani.xz.XZIOException;

/* renamed from: ᵘᵲʘᵶ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2539 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public long f9895;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final AbstractC2482 f9896;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public long f9897;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final CorruptedInputException f9898;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public long f9899;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public long f9900;

    public C2539() {
        CorruptedInputException corruptedInputException = new CorruptedInputException();
        this.f9899 = 0L;
        this.f9897 = 0L;
        this.f9900 = 0L;
        this.f9895 = 0L;
        this.f9898 = corruptedInputException;
        try {
            this.f9896 = new C2499(1);
        } catch (NoSuchAlgorithmException unused) {
            this.f9896 = new C2499(0);
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m6394(long j, long j2) throws CorruptedInputException {
        this.f9899 += (3 + j) & (-4);
        this.f9897 += j2;
        this.f9900 += ᵿᵧ.ᵢˇᵭ(j2) + ᵿᵧ.ᵢˇᵭ(j);
        this.f9895 = this.f9895 + 1;
        if (this.f9899 >= 0 && this.f9897 >= 0 && ((ᵿᵧ.ᵢˇᵭ(r5) + 1 + this.f9900 + 7) & (-4)) <= 17179869184L) {
            if (((ᵿᵧ.ᵢˇᵭ(this.f9895) + 1 + this.f9900 + 7) & (-4)) + this.f9899 + 12 + 12 >= 0) {
                ByteBuffer byteBufferAllocate = ByteBuffer.allocate(16);
                byteBufferAllocate.putLong(j);
                byteBufferAllocate.putLong(j2);
                byte[] bArrArray = byteBufferAllocate.array();
                AbstractC2482 abstractC2482 = this.f9896;
                abstractC2482.getClass();
                abstractC2482.mo6324(bArrArray, 0, bArrArray.length);
                return;
            }
        }
        throw this.f9898;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void m6395(InputStream inputStream) throws CorruptedInputException {
        CRC32 crc32 = new CRC32();
        crc32.update(0);
        CheckedInputStream checkedInputStream = new CheckedInputStream(inputStream, crc32);
        if (ᵿᵧ.ᵝᵵᵺ(checkedInputStream) != this.f9895) {
            throw new CorruptedInputException("XZ Block Header or the start of XZ Index is corrupt");
        }
        C2539 c2539 = new C2539();
        for (long j = 0; j < this.f9895; j++) {
            try {
                c2539.m6394(ᵿᵧ.ᵝᵵᵺ(checkedInputStream), ᵿᵧ.ᵝᵵᵺ(checkedInputStream));
                if (c2539.f9899 > this.f9899 || c2539.f9897 > this.f9897 || c2539.f9900 > this.f9900) {
                    throw new CorruptedInputException("XZ Index is corrupt");
                }
            } catch (XZIOException unused) {
                throw new CorruptedInputException("XZ Index is corrupt");
            }
        }
        if (c2539.f9899 != this.f9899 || c2539.f9897 != this.f9897 || c2539.f9900 != this.f9900 || !Arrays.equals(c2539.f9896.mo6322(), this.f9896.mo6322())) {
            throw new CorruptedInputException("XZ Index is corrupt");
        }
        DataInputStream dataInputStream = new DataInputStream(checkedInputStream);
        for (int i = (int) (3 & (4 - (((ᵿᵧ.ᵢˇᵭ(this.f9895) + 1) + this.f9900) + 4))); i > 0; i--) {
            if (dataInputStream.readUnsignedByte() != 0) {
                throw new CorruptedInputException("XZ Index is corrupt");
            }
        }
        long value = crc32.getValue();
        for (int i2 = 0; i2 < 4; i2++) {
            if (((value >>> (i2 * 8)) & 255) != dataInputStream.readUnsignedByte()) {
                throw new CorruptedInputException("XZ Index is corrupt");
            }
        }
    }
}
