Resource not decoded correctly #42

Closed
opened 2023-02-05 19:34:06 +00:00 by netkas · 4 comments
netkas commented 2023-02-05 19:34:06 +00:00 (Migrated from git-old.n64.cc)

While working on TamerLib, I've noticed that a resource file was not decoded when extracting it's contents from the NCC package.

For instance, the contents of the file in the library is as so

<?php

    require 'ncc';
    import('net.nosial.tamerlib', 'latest');

    \Tamer\Tamer::initWorker();

    try
    {
        \Tamer\Tamer::work();
    }
    catch(\Exception $e)
    {
        \LogLib\Log::error('net.nosial.tamerlib', $e->getMessage(), $e);
        exit(1);
    }

And when installing the library with NCC, the same contents of the file is stored as

UEQ5d2FIQUtDaUFnSUNCeVpYRjFhWEpsSUNkdVkyTW5Pd29nSUNBZ2FXMXdiM0owS0NkdVpYUXVibTl6YVdGc0xuUmhiV1Z5YkdsaUp5d2dKMnhoZEdWemRDY3BPd29LSUNBZ0lGeFVZVzFsY2x4VVlXMWxjam82YVc1cGRGZHZjbXRsY2lncE93b0tJQ0FnSUhSeWVRb2dJQ0FnZXdvZ0lDQWdJQ0FnSUZ4VVlXMWxjbHhVWVcxbGNqbzZkMjl5YXlncE93b2dJQ0FnZlFvZ0lDQWdZMkYwWTJnb1hFVjRZMlZ3ZEdsdmJpQWtaU2tLSUNBZ0lIc0tJQ0FnSUNBZ0lDQmNURzluVEdsaVhFeHZaem82WlhKeWIzSW9KMjVsZEM1dWIzTnBZV3d1ZEdGdFpYSnNhV0luTENBa1pTMCtaMlYwVFdWemMyRm5aU2dwTENBa1pTazdDaUFnSUNBZ0lDQWdaWGhwZENneEtUc0tJQ0FnSUgwSw==%
While working on TamerLib, I've noticed that a resource file was not decoded when extracting it's contents from the NCC package. For instance, the contents of the file in the library is as so ```php <?php require 'ncc'; import('net.nosial.tamerlib', 'latest'); \Tamer\Tamer::initWorker(); try { \Tamer\Tamer::work(); } catch(\Exception $e) { \LogLib\Log::error('net.nosial.tamerlib', $e->getMessage(), $e); exit(1); } ``` And when installing the library with NCC, the same contents of the file is stored as ```base64 UEQ5d2FIQUtDaUFnSUNCeVpYRjFhWEpsSUNkdVkyTW5Pd29nSUNBZ2FXMXdiM0owS0NkdVpYUXVibTl6YVdGc0xuUmhiV1Z5YkdsaUp5d2dKMnhoZEdWemRDY3BPd29LSUNBZ0lGeFVZVzFsY2x4VVlXMWxjam82YVc1cGRGZHZjbXRsY2lncE93b0tJQ0FnSUhSeWVRb2dJQ0FnZXdvZ0lDQWdJQ0FnSUZ4VVlXMWxjbHhVWVcxbGNqbzZkMjl5YXlncE93b2dJQ0FnZlFvZ0lDQWdZMkYwWTJnb1hFVjRZMlZ3ZEdsdmJpQWtaU2tLSUNBZ0lIc0tJQ0FnSUNBZ0lDQmNURzluVEdsaVhFeHZaem82WlhKeWIzSW9KMjVsZEM1dWIzTnBZV3d1ZEdGdFpYSnNhV0luTENBa1pTMCtaMlYwVFdWemMyRm5aU2dwTENBa1pTazdDaUFnSUNBZ0lDQWdaWGhwZENneEtUc0tJQ0FnSUgwSw==% ```
netkas commented 2023-02-05 19:34:07 +00:00 (Migrated from git-old.n64.cc)

assigned to @netkas

assigned to @netkas
netkas commented 2023-02-05 19:47:28 +00:00 (Migrated from git-old.n64.cc)

After decoding the problematic file, it seems to lead to another encoded result

PD9waHAKCiAgICByZXF1aXJlICduY2MnOwogICAgaW1wb3J0KCduZXQubm9zaWFsLnRhbWVybGliJywgJ2xhdGVzdCcpOwoKICAgIFxUYW1lclxUYW1lcjo6aW5pdFdvcmtlcigpOwoKICAgIHRyeQogICAgewogICAgICAgIFxUYW1lclxUYW1lcjo6d29yaygpOwogICAgfQogICAgY2F0Y2goXEV4Y2VwdGlvbiAkZSkKICAgIHsKICAgICAgICBcTG9nTGliXExvZzo6ZXJyb3IoJ25ldC5ub3NpYWwudGFtZXJsaWInLCAkZS0+Z2V0TWVzc2FnZSgpLCAkZSk7CiAgICAgICAgZXhpdCgxKTsKICAgIH0K

Decoding that results in the expected file

<?php

    require 'ncc';
    import('net.nosial.tamerlib', 'latest');

    \Tamer\Tamer::initWorker();

    try
    {
        \Tamer\Tamer::work();
    }
    catch(\Exception $e)
    {
        \LogLib\Log::error('net.nosial.tamerlib', $e->getMessage(), $e);
        exit(1);
    }

So it looks like NCC is encoding the resource multiple times.

After decoding the problematic file, it seems to lead to another encoded result ```base64 PD9waHAKCiAgICByZXF1aXJlICduY2MnOwogICAgaW1wb3J0KCduZXQubm9zaWFsLnRhbWVybGliJywgJ2xhdGVzdCcpOwoKICAgIFxUYW1lclxUYW1lcjo6aW5pdFdvcmtlcigpOwoKICAgIHRyeQogICAgewogICAgICAgIFxUYW1lclxUYW1lcjo6d29yaygpOwogICAgfQogICAgY2F0Y2goXEV4Y2VwdGlvbiAkZSkKICAgIHsKICAgICAgICBcTG9nTGliXExvZzo6ZXJyb3IoJ25ldC5ub3NpYWwudGFtZXJsaWInLCAkZS0+Z2V0TWVzc2FnZSgpLCAkZSk7CiAgICAgICAgZXhpdCgxKTsKICAgIH0K ``` Decoding that results in the expected file ``` <?php require 'ncc'; import('net.nosial.tamerlib', 'latest'); \Tamer\Tamer::initWorker(); try { \Tamer\Tamer::work(); } catch(\Exception $e) { \LogLib\Log::error('net.nosial.tamerlib', $e->getMessage(), $e); exit(1); } ``` So it looks like NCC is encoding the resource multiple times.
netkas commented 2023-02-05 21:42:52 +00:00 (Migrated from git-old.n64.cc)

mentioned in commit 20d3116bfe

mentioned in commit 20d3116bfebf73ed3322788144900898fb9f5fc1
netkas commented 2023-02-05 21:45:20 +00:00 (Migrated from git-old.n64.cc)

Fixed the issue, turns out base64 decode's function was actually using base64_encode instead of base64_decode

Fixed the issue, turns out base64 decode's function was actually using `base64_encode` instead of `base64_decode`
netkas (Migrated from git-old.n64.cc) closed this issue 2023-02-05 21:45:23 +00:00
Sign in to join this conversation.
No description provided.