public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Mike FABIAN <mfabian@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/foma] rawhide: Add patch from upstream to improve file reading
Date: Sun, 30 Aug 2026 21:04:35 GMT [thread overview]
Message-ID: <178812387562.1.10062875712336533616.rpms-foma-9bf8c6a79aa2@fedoraproject.org> (raw)
A new commit has been pushed.
Repo : rpms/foma
Branch : rawhide
Commit : 9bf8c6a79aa2050c7a561cd8351c64de5eae1a87
Author : Mike FABIAN <mfabian@redhat.com>
Date : 2026-08-20T12:30:44+02:00
Stats : +121/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/foma/c/9bf8c6a79aa2050c7a561cd8351c64de5eae1a87?branch=rawhide
Log:
Add patch from upstream to improve file reading
---
diff --git a/foma-improve-file-reading.patch b/foma-improve-file-reading.patch
new file mode 100644
index 0000000..caf1597
--- /dev/null
+++ b/foma-improve-file-reading.patch
@@ -0,0 +1,116 @@
+From 00600f0ff4904a7d5350c74fd1e0518c01cf0e44 Mon Sep 17 00:00:00 2001
+From: Mike FABIAN <mfabian@redhat.com>
+Date: Tue, 18 Aug 2026 11:35:49 +0200
+Subject: [PATCH] io.c: Improve file reading
+
+---
+ foma/io.c | 60 +++++++++++++++++++++++++++++++++++++++++++------------
+ 1 file changed, 47 insertions(+), 13 deletions(-)
+
+diff --git a/foma/io.c b/foma/io.c
+index da1c57a..9582871 100644
+--- a/foma/io.c
++++ b/foma/io.c
+@@ -920,6 +920,9 @@ int net_print_att(struct fsm *net, FILE *outfile) {
+ return(1);
+ }
+
++/* Limit uncompressed file size to avoid excessive memory allocation. */
++#define MAX_UNCOMPRESSED_FILE_SIZE (256 * 1024 * 1024)
++
+ static size_t io_get_gz_file_size(char *filename) {
+
+ FILE *infile;
+@@ -928,9 +931,18 @@ static size_t io_get_gz_file_size(char *filename) {
+ unsigned int ints[4], i;
+
+ /* The last four bytes in a .gz file shows the size of the uncompressed data */
+- infile = fopen(filename, "r");
+- fseek(infile, -4, SEEK_END);
+- fread(&bytes, 1, 4, infile);
++ infile = fopen(filename, "rb");
++ if (infile == NULL) {
++ return 0;
++ }
++ if (fseek(infile, -4, SEEK_END) != 0) {
++ fclose(infile);
++ return 0;
++ }
++ if (fread(bytes, 1, 4, infile) != 4) {
++ fclose(infile);
++ return 0;
++ }
+ fclose(infile);
+ for (i = 0 ; i < 4 ; i++) {
+ ints[i] = bytes[i];
+@@ -942,20 +954,28 @@ static size_t io_get_gz_file_size(char *filename) {
+ static size_t io_get_regular_file_size(char *filename) {
+
+ FILE *infile;
+- size_t numbytes;
+
+- infile = fopen(filename, "r");
+- fseek(infile, 0L, SEEK_END);
+- numbytes = ftell(infile);
++ infile = fopen(filename, "rb");
++ if (infile == NULL) {
++ return 0;
++ }
++ if (fseek(infile, 0L, SEEK_END) != 0) {
++ fclose(infile);
++ return 0;
++ }
++ long result = ftell(infile);
+ fclose(infile);
+- return(numbytes);
++ if (result < 0) {
++ return 0;
++ }
++ return (size_t) result;
+ }
+
+
+ static size_t io_get_file_size(char *filename) {
+ gzFile FILE;
+ size_t size;
+- FILE = gzopen(filename, "r");
++ FILE = gzopen(filename, "rb");
+ if (FILE == NULL) {
+ return(0);
+ }
+@@ -975,14 +995,28 @@ size_t io_gz_file_to_mem(struct io_buf_handle *iobh, char *filename) {
+ gzFile FILE;
+
+ size = io_get_file_size(filename);
+- if (size == 0) {
++ if (size == 0 || size > MAX_UNCOMPRESSED_FILE_SIZE) {
++ return 0;
++ }
++ iobh->io_buf = xxmalloc(size + 1);
++ if (iobh->io_buf == NULL) {
+ return 0;
+ }
+- (iobh->io_buf) = xxmalloc((size+1)*sizeof(char));
+ FILE = gzopen(filename, "rb");
+- gzread(FILE, iobh->io_buf, size);
++ if (FILE == NULL) {
++ free(iobh->io_buf);
++ iobh->io_buf = NULL;
++ return 0;
++ }
++ int nread = gzread(FILE, iobh->io_buf, size);
++ if (nread < 0 || (size_t)nread != size) {
++ gzclose(FILE);
++ free(iobh->io_buf);
++ iobh->io_buf = NULL;
++ return 0;
++ }
+ gzclose(FILE);
+- *((iobh->io_buf)+size) = '\0';
++ iobh->io_buf[size] = '\0';
+ iobh->io_buf_ptr = iobh->io_buf;
+ return(size);
+ }
+--
+2.55.0
+
diff --git a/foma.spec b/foma.spec
index 5da032b..0e268f8 100644
--- a/foma.spec
+++ b/foma.spec
@@ -9,7 +9,7 @@
Name: foma
Version: 0.10.0
-Release: 0.16.%{snapshotdate}git%{shortcommit0}%{?dist}
+Release: 0.17.%{snapshotdate}git%{shortcommit0}%{?dist}
Summary: Xerox-compatible finite-state compiler
License: Apache-2.0
@@ -28,6 +28,7 @@ Source0: https://github.com/mhulden/%{name}/archive/%{commit0}.tar.gz#/%{
Patch0: foma-harden-build-fedora.patch
Patch1: foma-c99.patch
Patch2: foma-avoid-deprecated-inet-functions.patch
+Patch3: foma-improve-file-reading.patch
BuildRequires: gcc zlib-devel readline-devel flex bison
BuildRequires: make
@@ -106,6 +107,9 @@ find %{buildroot} -name '*.a' -exec rm -f {} ';'
%changelog
+* Thu Aug 20 2026 Mike FABIAN <mfabian@redhat.com> - 0.10.0-0.17.20210601gitdfe1ccb
+- Add patch from upstream to improve file reading
+
* Wed Jul 15 2026 Fedora Release Engineering <releng@fedoraproject.org> - 0.10.0-0.16.20210601gitdfe1ccb
- Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
reply other threads:[~2026-08-30 21:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178812387562.1.10062875712336533616.rpms-foma-9bf8c6a79aa2@fedoraproject.org \
--to=mfabian@redhat.com \
--cc=git-commits@fedoraproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox