consumet / consumet.ts

Nodejs library that provides high-level APIs for obtaining information on various entertainment media such as books, movies, comic books, anime, manga, and so on.
https://consumet.org/extensions/list/
GNU General Public License v3.0
376 stars 205 forks source link

ZORO fetchEpisodeSources() throws error #517

Closed abhishek-exists closed 2 months ago

abhishek-exists commented 2 months ago

Describe the bug

fetchEpisodeSources() method is returning following error

Steps to reproduce

Run the zoro test using jest.

Its only failing for fetchEpisodeSources() method

Expected behavior

It should load episode sources.

Actual behavior

Its Breaking while decrypting the contents.

Additional context

Code block responsible from file extractors/megacloud.ts:

decrypt(encrypted: string, keyOrSecret: string, maybe_iv?: string) {
    let key;
    let iv;
    let contents;
    if (maybe_iv) {
      key = keyOrSecret;
      iv = maybe_iv;
      contents = encrypted;
    } else {
      const cypher = Buffer.from(encrypted, "base64");
      const salt = cypher.subarray(8, 16);
      const password = Buffer.concat([
        Buffer.from(keyOrSecret, "binary"),
        salt,
      ]);
      const md5Hashes = [];
      let digest = password;
      for (let i = 0; i < 3; i++) {
        md5Hashes[i] = crypto.createHash("md5").update(digest).digest();
        digest = Buffer.concat([md5Hashes[i], password]);
      }
      key = Buffer.concat([md5Hashes[0], md5Hashes[1]]);
      iv = md5Hashes[2];
      contents = cypher.subarray(16);
    }

    const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
    const decrypted =
      decipher.update(
        contents as any,
        typeof contents === "string" ? "base64" : undefined,
        "utf8"
      ) + decipher.final();

    return decrypted;
  }

Error thrown while processing following line

decipher.final()

Error:

Error: error:1C80006B:Provider routines::wrong final block length
    at Decipheriv.final (node:internal/crypto/cipher:193:29)

Suggestions: I'm not aware of the encryption process but it seems like contents is of size 482 which is not a multiple of 16. Not sure whether this will solve the issue or not.

CC: @riimuru @jasanpreetn9

Kylart commented 2 months ago

I can give some insights into this: it seems that the extractVariables method is returning empty string which might be the source of the problem. Maybe the regex needs updating?

abhishek-exists commented 2 months ago

Awesome @Kylart , I can verify that Zoro is working

Update: It worked when I made those changes but after few tries, its throwing same error