FS#78620 - [enca] truncates file to 0 byte

Attached to Project: Arch Linux
Opened by xiao pan (flylightning) - Saturday, 27 May 2023, 01:47 GMT
Last edited by Antonio Rojas (arojas) - Saturday, 27 May 2023, 06:27 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

# FIX IS PROVIDED

# Description:

`enca -L zh -x UTF-8 a.txt` truncates file to 0 byte

# Additional info:

Package version: 1.19-4

Links to upstream bug report:
- <https://github.com/nijel/enca/issues/33>
- <https://github.com/nijel/enca/issues/28>
- <https://github.com/rrthomas/recode/issues/4>

According to <https://github.com/nijel/enca/issues/33#issuecomment-569069061>, this is due to old enca-bad-file-descriptor.patch, delete that patch will fix this issue. See quotes from the issue comment:

> #28 seems to be solved by recode rrthomas/recode#4.
>
> I also use Arch and was able to build working version of the enca by not applying the patch which is enclosed with the PKGBUILD. (The patch was created by me and it was a workaround rather than a solution. And it seems to not longer work).
>
> I will send email to the maintainer of the PKGBUILD.

Quotes from <https://github.com/nijel/enca/issues/28#issuecomment-569065403>:

> It seems to be resolved by recode rrthomas/recode#4, which also solves #29.

After I deleted enca-bad-file-descriptor.patch and edited the PKGBUILD, I tested it with `enca -L zh -x UTF-8 a.txt` and this issue is fixed. **However, I didn't test if this fix will cause regression or not.**

# Steps to reproduce:

`enca -L zh -x UTF-8 a.txt`

See attached file a.txt for a.txt

# FIX

See attached file enca_fix_truncates_to_zero_byte.patch for fix. Here's also plain text:

```
From 7d5848153b8c6d2980f4cdd4403b5c397a16a2bb Mon Sep 17 00:00:00 2001
From: Xiao Pan <gky44px1999@gmail.com>
Date: Fri, 26 May 2023 18:30:39 -0700
Subject: [PATCH] fix `enca -L zh -x UTF-8 a.txt` truncates file to 0 byte

---
PKGBUILD | 12 +++---------
enca-bad-file-descriptor.patch | 35 ----------------------------------
2 files changed, 3 insertions(+), 44 deletions(-)
delete mode 100644 enca-bad-file-descriptor.patch

diff --git a/PKGBUILD b/PKGBUILD
index e630e6a..8dcef5c 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -3,21 +3,15 @@

pkgname=enca
pkgver=1.19
-pkgrel=4
+pkgrel=5
pkgdesc="Charset analyser and converter"
arch=('x86_64')
url="https://cihar.com/software/enca/"
license=('GPL')
depends=('recode')
options=('!docs')
-source=("https://dl.cihar.com/${pkgname}/${pkgname}-${pkgver}.tar.xz" enca-bad-file-descriptor.patch)
-sha256sums=('3a487eca40b41021e2e4b7a6440b97d822e6532db5464471f572ecf77295e8b8'
- '270c7c0abaea5f3d10173b58849200d4106675d3127a0b9b8ce1fc3dcf775acb')
-
-prepare() {
- cd $pkgname-$pkgver
- patch -p1 -i ../enca-bad-file-descriptor.patch # https://github.com/nijel/enca/issues/28
-}
+source=("https://dl.cihar.com/${pkgname}/${pkgname}-${pkgver}.tar.xz")
+sha256sums=('3a487eca40b41021e2e4b7a6440b97d822e6532db5464471f572ecf77295e8b8')

build() {
cd ${pkgname}-${pkgver}
diff --git a/enca-bad-file-descriptor.patch b/enca-bad-file-descriptor.patch
deleted file mode 100644
index 2f6ad91..0000000
--- a/enca-bad-file-descriptor.patch
+++ /dev/null
@@ -1,35 +0,0 @@
---- a/src/convert_recode.c
-+++ b/src/convert_recode.c
-@@ -101,7 +101,8 @@ convert_recode(File *file,
- return ERR_IOFAIL;
- file->buffer->pos = 0;
-
-- if ((tempfile = file_temporary(file->buffer, 1)) == NULL
-+ /* We do not unlink tempfile, because we want to reopen it later */
-+ if ((tempfile = file_temporary(file->buffer, 0)) == NULL
- || file_seek(file, 0, SEEK_SET) != 0) {
- file_free(tempfile);
- return ERR_IOFAIL;
-@@ -112,9 +113,20 @@ convert_recode(File *file,
- task->fail_level = enca_recode_fail_level;
- task->abort_level = RECODE_SYSTEM_ERROR;
- task->input.name = NULL;
-- task->input.file = file->stream;
- task->output.name = NULL;
-- task->output.file = tempfile->stream;
-+ /* recode_perform_task closes given streams, so we need to duplicate them */
-+ task->input.file = fopen(file->name, "rb");
-+ if (task->input.file == NULL) {
-+ fprintf(stderr, "failed to reopen `%s'\n", file->name);
-+ file_free(tempfile);
-+ return ERR_IOFAIL;
-+ }
-+ task->output.file = fopen(tempfile->name, "wb");
-+ if (task->input.file == NULL) {
-+ fprintf(stderr, "failed to reopen `%s'\n", tempfile->name);
-+ file_free(tempfile);
-+ return ERR_IOFAIL;
-+ }
-
- /* Now run conversion original -> temporary file. */
- success = recode_perform_task(task);
--
2.40.1
```
This task depends upon

Closed by  Antonio Rojas (arojas)
Saturday, 27 May 2023, 06:27 GMT
Reason for closing:  Fixed
Additional comments about closing:  enca 1.19-5
Comment by xiao pan (flylightning) - Saturday, 27 May 2023, 01:57 GMT
This bug report is for package enca: <https://archlinux.org/packages/extra/x86_64/enca/>

Sorry for not putting [enca] at the beginning of the title. The first time I tried to submit, I put [enca] at the beginning of the title, but the webpage made a flicking and failed to submit. The second time when I tried to submit the bug report, I forgot to add [enca] at the beginning of the title.
Comment by Toolybird (Toolybird) - Saturday, 27 May 2023, 02:48 GMT
Thanks, but it's an orphaned pkg i.e. no Arch pkg maintainer. Notifying the PM of mplayer (the only pkg that depends on it) and also the PM who committed the patch.

Loading...